Using ISO 8601 SAS Informats and Formats to Import Time Values with a Time Zone

This example illustrates importing an XML document that contains time values in various forms. The XMLMap uses the FORMAT and INFORMAT elements to specify the appropriate SAS formats and SAS informats in order to represent the times appropriately.
Here is an XML document that contains a variety of time values:
<?xml version="1.0" ?>
<Root>
  <TIME>
    <LOCAL>09:00:00</LOCAL>
    <UTC>09:00:00Z</UTC>
    <OFFSET>14:00:00+05:00</OFFSET>
  </TIME>
</Root>
The following XMLMap imports the XML document using the SAS informats and formats to read and write the time values:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ############################################################ -->
<!-- 2011-01-11T13:31:41 -->
<!-- SAS XML Libname Engine Map -->
<!-- Generated by XML Mapper, 903000.1.0.20101208190000_v930 -->
<!-- ############################################################ -->
<!-- ###  Validation report                                   ### -->
<!-- ############################################################ -->
<!-- XMLMap validation completed successfully. -->
<!-- ############################################################ -->
<SXLEMAP name="ISOtime" version="2.1">

    <NAMESPACES count="0"/>

    <!-- ############################################################ -->
    <TABLE name="TIME">
        <TABLE-PATH syntax="XPath">/Root/TIME</TABLE-PATH>

        <COLUMN name="LOCAL">
            <PATH syntax="XPath">/Root/TIME/LOCAL</PATH>
            <TYPE>numeric</TYPE>
            <DATATYPE>time</DATATYPE>
            <FORMAT width="8">E8601TM</FORMAT> 1
            <INFORMAT width="8">E8601TM</INFORMAT>
        </COLUMN>

        <COLUMN name="LOCALZONE">
            <PATH syntax="XPath">/Root/TIME/LOCAL</PATH>
            <TYPE>numeric</TYPE>
            <DATATYPE>time</DATATYPE>
            <FORMAT width="14">E8601LZ</FORMAT> 2
            <INFORMAT width="8">E8601TM</INFORMAT>
        </COLUMN>

        <COLUMN name="UTC">
            <PATH syntax="XPath">/Root/TIME/UTC</PATH>
            <TYPE>numeric</TYPE>
            <DATATYPE>time</DATATYPE>
            <FORMAT width="9">E8601TZ</FORMAT> 3
            <INFORMAT width="9">E8601TZ</INFORMAT>
        </COLUMN>

        <COLUMN name="OFFSET">
            <PATH syntax="XPath">/Root/TIME/OFFSET</PATH>
            <TYPE>numeric</TYPE>
            <DATATYPE>time</DATATYPE>
            <FORMAT width="14">E8601TZ</FORMAT> 4
            <INFORMAT width="14">E8601TZ</INFORMAT>
        </COLUMN>

    </TABLE>

</SXLEMAP>
The following explains the XMLMap syntax that imports the time values:
Note: Even with the time notation, it is recommended that you do not mix time-based values.
1 For the Local variable, the INFORMAT and FORMAT elements specify the E8601TM SAS informat and format, which reads and writes time values in the extended format hh:mm:ss.ffffff. Because there is no time zone indicator, the context of the value is local time.
2 For the Localzone variable, which reads the same value as the Local variable, the INFORMAT element specifies the E8601TM SAS informat, which reads time values in the extended format hh:mm:ss.ffffff. Because there is no time zone indicator, the context of the value is local time.
The FORMAT element, however, specifies the E8601LZ SAS format, which writes time values in the extended format hh:mm:ss+|-hh:mm. The E8601LZ format appends the UTC offset to the value as determined by the local, current SAS session. Using the E8601LZ format enables you to provide a time notation in order to eliminate the ambiguity of local time.
Note: Even with the time notation, it is recommended that you do not mix time-based values.
3 For the UTC variable, the INFORMAT and FORMAT elements specify the E8601TZ SAS informat and format, which reads and writes time values in the extended format hh:mm:ss+|-hh:mm. Because there is a time zone indicator, the value is assumed to be expressed in UTC. No adjustment or conversion is made to the value.
4 For the Offset variable, the INFORMAT and FORMAT elements specify the E8601TZ SAS informat and format, which reads and writes time values in the extended format hh:mm:ss+|-hh:mm. Because there is a time zone offset present, when the time value is read into the variable using the time zone-sensitive SAS informat, the value is adjusted to UTC as requested via the time zone indicator, but the time zone context is not stored with the value. When the time value is written using the time zone—sensitive SAS format, the value is expressed as UTC with a zero offset value and is not adjusted to or from local time.
The following SAS statements import the XML document and display the PRINT procedure output:
filename timzn 'c:\My Documents\XML\Time.xml';
filename map 'c:\My Documents\XML\Time.map';

libname timzn xmlv2 xmlmap=map;

proc print data=timzn.time;
run; 
PRINT Procedure Output for Imported Data Set TIMZN.TIME
PRINT Procedure Output for Imported Data Set TIMZN.TIME