SAS Institute. The Power to Know

FOCUS AREAS

Return to previous page

Base SAS

Example: Importing Both Basic Format and Extended Format Dates

This simple example illustrates how to import 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.

First, 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"?>
<SXLEMAP version="1.2" name="ISOdate"
      description="Reading a Basic and Extended format ISO date field">
  <!-- ############################################################ -->
  <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">IS8601DA</FORMAT>
      <INFORMAT width="8">ND8601DA</INFORMAT>
    </COLUMN>

    <COLUMN name="EXTENDED">
      <PATH  syntax="XPath">/Root/ISODATE/EXTENDED</PATH>
      <TYPE>numeric</TYPE>
      <DATATYPE>date</DATATYPE>
      <FORMAT>IS8601DA</FORMAT>
      <INFORMAT>IS8601DA</INFORMAT>
    </COLUMN>

  </TABLE>

</SXLEMAP>

The following explains the XMLMap syntax that imports the date values:

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 xml xmlmap=map;

   proc print data=dates.isodate;
   run;

PRINT Procedure Output for Imported Data Set DATES.ISODATE

                     The SAS System               1

               Obs    BASIC          EXTENDED

                 1    2001-09-11    2001-09-11