| 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 the EXPORT markup type, which is an XML markup type for transporting files across hosts. 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 xml92 xmltype=export '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, specifies the XML92 engine nickname, and then specifies the EXPORT markup type.
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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="SXLEexport.xsd"
type="EXPORT" version="9.2">
<LIBRARY-HEADER>
<Provider>SAS Institute Inc.</Provider>
<Version>9.2</Version>
<VersionLong>9.02.02B0D03192008</VersionLong>
<CreationDateTime>2008-03-20T13:51:10</CreationDateTime>
</LIBRARY-HEADER>
<TABLE name="CLASS">
<TABLE-HEADER>
<Provider>SAS Institute Inc.</Provider>
<Version>9.2</Version>
<VersionLong>9.02.02B0D03192008</VersionLong>
<CreationDateTime>2008-03-20T13:51:10</CreationDateTime>
<ModifiedDateTime>2008-03-20T13:51:10</ModifiedDateTime>
<Protection />
<DataSetType />
<DataRepresentation />
<Encoding>windows-1252</Encoding>
<ReleaseCreated />
<HostCreated />
<FileName>C:\My Documents\XML\Trans.xml</FileName>
<Observations length="40" />
<Compression compressed="No" number="1" length="56" />
<SortAssertion sorted="false" />
<SystemOption missing="." />
<Variables number="5" />
</TABLE-HEADER>
<TABLE-METADATA>
<COLUMN order="1" name="Name">
<TYPE>character</TYPE>
<DATATYPE>string</DATATYPE>
<LENGTH>8</LENGTH>
<Offset>0</Offset>
</COLUMN>
<COLUMN order="2" name="Sex">
<TYPE>character</TYPE>
<DATATYPE>string</DATATYPE>
<LENGTH>1</LENGTH>
<Offset>8</Offset>
</COLUMN> <COLUMN order="3" name="Age">
<TYPE>numeric</TYPE>
<DATATYPE>float</DATATYPE>
<Offset>9</Offset>
</COLUMN>
</TABLE-METADATA>
.
.
.
<TABLE-DATA>
<DATA>
<DATUM name="Name">Alfred</DATUM>
<DATUM name="Sex">M</DATUM>
<DATUM-NUMERIC name="Age" rawvalue="QeAAAAAAAAA=">14</DATUM-NUMERIC>
<DATUM-NUMERIC name="Height" rawvalue="QkUAAAAAAAA=">69</DATUM-NUMERIC>
<DATUM-NUMERIC name="Weight" rawvalue="QnCAAAAAAAA=">112.5</DATUM-NUMERIC>
</DATA>
<DATA>
<DATUM name="Name">Alice</DATUM>
<DATUM name="Sex">F</DATUM>
<DATUM-NUMERIC name="Age" rawvalue="QdAAAAAAAAA=">13</DATUM-NUMERIC>
<DATUM-NUMERIC name="Height" rawvalue="QjiAAAAAAAA=">56.5</DATUM-NUMERIC>
<DATUM-NUMERIC name="Weight" rawvalue="QlQAAAAAAAA=">84</DATUM-NUMERIC>
</DATA>
.
.
.
</TABLE-DATA>
</TABLE>
</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 xml92 'XML-document' xmltype=export ; 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, specifies the XML92 engine nickname, and then specifies the EXPORT markup type.
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 © 2008 by SAS Institute Inc., Cary, NC, USA. All rights reserved.