Creating an XML Document at the Source Machine


Using the DATA Step to Create an XML Document From a Data Set

This example uses the DATA step with the XML engine to create an XML document from a data set.

 libname source '  SAS-data-library  '; libname xmlout xml '  XML-document  '; data xmlout.grades;   set source.grades; run; 

In the preceding example, the libref SOURCE points to the location of the library that is on the source machine. The libref XMLOUT points to the location where the XML document will be created. The XML engine in this LIBNAME statement specifies that the file is to be created in XML markup. The SET statement reads the data set GRADES and generates XML markup at the location that is specified in the LIBNAME statement.

Here are the contents of the resulting XML document:

Output 5.1: XML Output Generated from Data Set GRADES
start example
 <?xml version="1.0" encoding="windows-1252" ?> <TABLE>    <GRADES>        <student> Fred </student>        <test1> 66 </test1>        <test2> 80 </test2>        <final> 90 </final>    </GRADES>    <GRADES>        <student> Wilma </student>        <test1> 97 </test1>        <test2> 91 </test2>        <final> 98 </final>    </GRADES> </TABLE> 
end example
 

Using PROC COPY to Create an XML Document From a Data Set

This example uses the COPY procedure to create an XML document from a data set.

 libname source '  SAS-data-library  '; libname xmlout xml '  XML-document  '; proc copy in=source out=xmlout;   select grades; run; 

In the preceding example, the libref SOURCE points to the location of the library that is on the source machine. The libref XMLOUT points to the location where the XML document will be created. The XML engine in this LIBNAME statement specifies that the file is to be created in XML markup. The PROC COPY statement copies data from the library that is identified in the IN= option to the library that is identified in the OUT= option. The SELECT statement specifies which data set will be copied from the input library.

Note  

If you do not specify a single data set in the SELECT statement, the XML engine will process all members of the input library. However, because an XML document can contain only one data set, only the last data set that is processed remains in the resulting XML document.




Moving and Accessing SAS 9.1 Files
Moving And Accessing SAS 9.1 Files
ISBN: 1590472306
EAN: 2147483647
Year: 2004
Pages: 109
Authors: SAS Institute

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net