Using ISO 8601 SAS Informats and Formats to Import Dates

This simple example illustrates importing an XML document that contains date values in both the basic format and the extended format. The XMLMap uses the FORMAT and INFORMAT elements to specify the appropriate SAS format and SAS informat in order to represent the dates according to ISO 8601 standards.
Here is the XML document:
<?xml version="1.0" ?>
<Root>
  <ISODATE>
    <BASIC>20010911</BASIC>
    <EXTENDED>2001-09-11</EXTENDED>
  </ISODATE>
</Root>
The following XMLMap imports the XML document using the SAS informats and formats to read and write the date values:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ############################################################ -->
<!-- 2011-01-11T13:20:17 -->
<!-- SAS XML Libname Engine Map -->
<!-- Generated by XML Mapper, 903000.1.0.20101208190000_v930 -->
<!-- ############################################################ -->
<!-- ###  Validation report                                   ### -->
<!-- ############################################################ -->
<!-- XMLMap validation completed successfully. -->
<!-- ############################################################ -->
<SXLEMAP description="Reading a Basic and Extended format ISO date field" 
   name="ISOdate" version="2.1">

    <NAMESPACES count="0"/>

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

        <COLUMN name="BASIC">
            <PATH syntax="XPath">/Root/ISODATE/BASIC</PATH>
            <TYPE>numeric</TYPE>
            <DATATYPE>date</DATATYPE>
            <FORMAT width="10">E8601DA</FORMAT> 1
            <INFORMAT width="8">B8601DA</INFORMAT> 2
        </COLUMN>

        <COLUMN name="EXTENDED">
            <PATH syntax="XPath">/Root/ISODATE/EXTENDED</PATH>
            <TYPE>numeric</TYPE>
            <DATATYPE>date</DATATYPE>
            <FORMAT>E8601DA</FORMAT> 3
            <INFORMAT width="10">E8601DA</INFORMAT> 4
        </COLUMN>

    </TABLE>

</SXLEMAP>
The following explains the XMLMap syntax that imports the date values:
Note: As recommended, when you read values into a variable with a basic format SAS informat, this example writes the values with the corresponding extended format SAS format.
1 For the Basic variable, the FORMAT element specifies the E8601DA SAS format, which writes data values in the extended format yyyy-mm-dd.
2 For the Basic variable, the INFORMAT element specifies the B8601DA SAS informat, which reads date values into a variable in the basic format yyyymmdd.
Note: As recommended, when you read values into a variable with a basic format SAS informat, this example writes the values with the corresponding extended format SAS format.
3 For the Extended variable, the FORMAT element specifies the E8601DA SAS format, which writes data values in the extended format yyyy-mm-dd.
4 For the Extended variable, the INFORMAT element specifies the E8601DA SAS informat, which reads date values into a variable in the basic format yyyy-mm-dd.
The following SAS statements import the XML document and display PRINT procedure output:
filename dates 'c:\My Documents\XML\ISOdate.xml';
filename map 'c:\My Documents\XML\ISOdate.map';

libname dates xmlv2 xmlmap=map;

proc print data=dates.isodate;
run;   
PRINT Procedure Output for Imported Data Set DATES.ISODATE
PRINT Procedure Output for Imported Data Set DATES.ISODATE