This sample program on the Full Code tab demonstrates working with ISO 8601 extended notation datetime values in the form of yyyy-mm-ddThh:mm:ss+|–hh:mm.<fffff>, to read in the datetime value with or without the offset, and shows how to preserve the original offset value. Once an offset is read and applied, you cannot produce the original offset value unless the value is read as character and the time zone offset is kept in a separate variable.
The INPUT statement in the sample program reads the same ISO 8601 extended notation datetime value from each data line into three separate variables. The first variable named UTC uses the E8601DZ32.6 informat to read the Coordinated Universal Time (UTC) datetime value, and adjusts the datetime by the given offset hour and minute in the local time zone. The second variable named DT uses the E8601DT26.6 informat to read the datetime value, excluding the offset, into a SAS® datetime using the local time zone. The third variable named CHAR_DT uses the $32. informat to read the entire value including the offset into a character variable.
If you need to display or write out the datetime value in the same format as the input value with the original offset value, you must read the original value into a character variable and store the offset in a separate variable.
If you need to read in the datetime value without the offset, make adjustments to the datetime within the program, and display or write out the adjusted datetime in the same format as the input value with the original offset value, you will need to create a new character variable concatenating the date part and time part with the original offset.
Adjustments to the datetime are shown in the sample program with the variable named ADJUSTED_DT that uses the INTNX function to adjust the DT variable by one day. The offset is stored in a character variable named CHAR_OFFSET by using the INDEX function and SCAN function. The new adjusted character datetime is created and put back into the original input format of yyyy-mm-ddThh:mm:ss+|–hh:mm.<fffff>, by concatenating the date, time, and offset values, using the PUT function, DATEPART function, TIMEPART function, and STRIP function.
Here are links to the SAS® 9.4 Formats and Informats: Reference, for the E8601DZw.d Informat and the E8601DTw.d Informat
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
options timezone="EDT";
data test;
input utc e8601dz32.6 @1 dt e8601dt26.6 @1 char_dt $32.;
format utc e8601dz32.6 dt e8601dt26.6 ;
adjusted_dt=intnx('dtday',dt,1,"s"); /*datetime adjusted by 1 day*/
format adjusted_dt e8601dt26.6;
length char_offset $ 6;
if index(char_dt,"+") > 0 then char_offset="+"||scan(char_dt,-1,"+-");
else char_offset="-"||scan(char_dt,-1,"+-");
char_adjusted_dt=put(datepart(adjusted_dt),e8601da10.)||"T"||put(timepart(adjusted_dt),time15.6)||strip(char_offset);
datalines;
2015-10-02T17:15:43.187802-04:00
2015-10-02T17:15:43.187802+04:00
;
run;
proc print data=test;
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
The SAS System Obs utc dt char_dt 1 2015-10-02T21:15:43.187802+00:00 2015-10-02T17:15:43.187802 2015-10-02T17:15:43.187802-04:00 2 2015-10-02T13:15:43.187802+00:00 2015-10-02T17:15:43.187802 2015-10-02T17:15:43.187802+04:00 char_ Obs adjusted_dt offset char_adjusted_dt 1 2015-10-03T17:15:43.187802 -04:00 2015-10-03T17:15:43.187802-04:00 2 2015-10-03T17:15:43.187802 +04:00 2015-10-03T17:15:43.187802+04:00
Type: | Sample |
Date Modified: | 2015-11-20 15:43:57 |
Date Created: | 2015-11-12 14:11:19 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | z/OS | ||
z/OS 64-bit | ||||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 8.1 Enterprise 32-bit | ||||
Microsoft Windows 8.1 Enterprise x64 | ||||
Microsoft Windows 8.1 Pro | ||||
Microsoft Windows 8.1 Pro 32-bit | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 R2 Datacenter | ||||
Microsoft Windows Server 2012 R2 Std | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |