Creating an XML Document at the Source Computer

Example: 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 computer. 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:
XML Output Generated from Data Set GRADES
<?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>

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 computer. The libref XMLOUT points to the location at which 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 the data set that will be copied from the input library.
Note: If you do not specify a single data set in the SELECT statement, the XML engine processes all members of the input library and concatenates the observations.