Importing XML Documents Using an XMLMap |
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.
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"?> <!-- ############################################################ --> <!-- 2003-08-22T13:54:16 --> <!-- SAS XML Libname Engine Map --> <!-- Generated by XML Mapper, 9.1.10.20030602.99000 --> <!-- ############################################################ --> <!-- ### Validation report ### --> <!-- ############################################################ --> <!-- Map validation completed successfully. --> <!-- ############################################################ --> <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">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:
For the Basic variable, the FORMAT element specifies the E8601DA SAS format, which writes data values in the extended format YYYY-MM-DD.
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.
For the Extended variable, the FORMAT element specifies the E8601DA SAS format, which writes data values in the extended format YYYY-MM-DD.
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 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
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.