| Using the XML Engine to Transport SAS Data Sets across Operating Environments |
This example exports an XML document from a SAS data set on a source host, and then imports the XML document to a SAS data set on a target host. The XML engine uses all defaults; for example, the markup type is GENERIC, which is a simple, well-formed XML markup. The COPY procedure reads the SAS data set and writes its content in XML markup. Then, the DATA step reads the XML document and writes its content to a SAS data set.
The following output shows the SAS data set MYFILES.CLASS to be moved to another host.
SAS Data Set MYFILES.CLASS to Be Exported
Obs Name Gender Age Height Weight
1 Alfred M 14 69.0 112.5
2 Alice F 13 56.5 84.0
3 Barbara F 13 65.3 98.0
4 Carol F 14 62.8 102.5
5 Henry M 14 63.5 102.5
6 James M 12 57.3 83.0
7 Jane F 12 59.8 84.5
8 Janet F 15 62.5 112.5
9 Jeffrey M 13 62.5 84.0
10 John M 12 59.0 99.5
11 Joyce F 11 51.3 50.5
12 Judy F 14 64.3 90.0
13 Louise F 12 56.3 77.0
14 Mary F 15 66.5 112.0
15 Philip M 16 72.0 150.0
16 Robert M 12 64.8 128.0
17 Ronald M 15 67.0 133.0
18 Thomas M 11 57.5 85.0
19 William M 15 66.5 112.0
The following SAS program exports an XML document on the source host for the SAS data set MYFILES.CLASS:
libname myfiles 'SAS-library'; 1 libname trans xml 'XML-document' ; 2 proc copy in=myfiles out=trans; 3 select class; run;
The first LIBNAME statement assigns the libref MYFILES to the physical location of the SAS library that stores the SAS data set CLASS in SAS proprietary format. The V9 engine is the default.
The second LIBNAME statement assigns the libref TRANS to the physical location of the file (complete pathname, filename, and file extension) that will store the exported XML document, and then specifies the XML engine. By default, the XML engine generates GENERIC format.
The COPY procedure reads the SAS data set MYFILES.CLASS and writes its content in XML markup to the specified file.
Here is the resulting XML document.
XML Document Exported from MYFILES.CLASS
<
?xml version="1.0" encoding="windows-1252" ?>
<LIBRARY type="GENERIC" version="9.2">
<CLASS>
<Name>Alfred</Name>
<Sex>M</Sex>
<Age>14</Age>
<Height>69</Height>
<Weight>112.5</Weight>
</CLASS>
<CLASS>
<Name>Alice</Name>
<Sex>F</Sex>
<Age>13</Age>
<Height>56.5</Height>
<Weight>84</Weight>
</CLASS>
.
.
.
<CLASS>
<Name>William</Name>
<Sex>M</Sex>
<Age>15</Age>
<Height>66.5</Height>
<Weight>112</Weight>
</CLASS>
</LIBRARY>
After the XML document is exported on the source host, it must be transferred from the source host to the target host. Then, with the XML document available on the target host, the following SAS program translates the XML markup to SAS proprietary format:
libname trans xml 'XML-document' ; 1 libname myfiles 'SAS-library'; 2 data myfiles.class; 3 set trans.class; run;
The first LIBNAME statement assigns the libref TRANS to the physical location of the XML document (complete pathname, filename, and file extension) that was transferred to the target host, and specifies the XML engine. By default, the XML engine expects GENERIC format.
The second LIBNAME statement assigns the libref MYFILES to the physical location of the SAS library to store the resulting SAS data set. The V9 engine is the default.
The DATA step reads the XML document and writes its content in SAS proprietary format.
Issuing the PRINT procedure produces the output for the data set that was translated from the XML document:
proc print data=myfiles.class; run;
PROC PRINT Output for MYFILES.CLASS Moved to Another Host by Importing XML Document
The SAS System 1
Obs WEIGHT HEIGHT AGE GENDER NAME
1 112.5 69.0 14 M Alfred
2 84.0 56.5 13 F Alice
3 98.0 65.3 13 F Barbara
4 102.5 62.8 14 F Carol
5 102.5 63.5 14 M Henry
6 83.0 57.3 12 M James
7 84.5 59.8 12 F Jane
8 112.5 62.5 15 F Janet
9 84.0 62.5 13 M Jeffrey
10 99.5 59.0 12 M John
11 50.5 51.3 11 F Joyce
12 90.0 64.3 14 F Judy
13 77.0 56.3 12 F Louise
14 112.0 66.5 15 F Mary
15 150.0 72.0 16 M Philip
16 128.0 64.8 12 M Robert
17 133.0 67.0 15 M Ronald
18 85.0 57.5 11 M Thomas
19 112.0 66.5 15 M William
Copyright © 2007 by SAS Institute Inc., Cary, NC, USA. All rights reserved.