SAS Institute. The Power to Know

FOCUS AREAS

Return to previous page

Base SAS

Generating an XML Document to Export for Use by ORACLE

This example generates an output XML document from a SAS data set to be exported for use by ORACLE. By specifying the ORACLE format, the XML engine generates tags that are specific to ORACLE standards.

The following output shows the SAS data set MYFILES.CLASS to be exported to ORACLE:

                                 The SAS System                                1

                Obs    Name       Sex    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 generates an output XML document from the SAS data set MYFILES.CLASS:

libname myfiles 'SAS-library'; [1]   

libname trans xml 'external-file' xmltype=oracle; [2]   

proc copy in=myfiles out=trans; [3]   
   select class;
run;

  1. The first LIBNAME statement assigns the libref MYFILES to the physical location of the SAS library that stores the SAS data set CLASS. The V8 base engine is the default.

  2. The second LIBNAME statement assigns the libref TRANS to the physical location of the file that will store the generated XML document (complete pathname and file name) and specifies the XML engine. The engine option XMLTYPE=ORACLE produces tags that are equivalent to the Oracle8iXML implementation.

  3. The COPY procedure reads the SAS data set MYFILES.CLASS and writes its content in ORACLE XML format to the specified file.

The resulting XML document is as follows:

<?xml version="1.0" ?>
<ROWSET>
 <ROW>
  <Name> Alfred </Name>
  <Sex> M </Sex>
  <Age> 14 </Age>
  <Height> 69 </Height>
  <Weight> 112.5 </Weight>
 </ROW>
 <ROW>
  <Name> Alice </Name>
  <Sex> F </Sex>
  <Age> 13 </Age>
  <Height> 56.5 </Height>
  <Weight> 84 </Weight>
 </ROW>
.
.
.
 <ROW>
  <Name> William </Name>
  <Sex> M </Sex>
  <Age> 15 </Age>
  <Height> 66.5 </Height>
  <Weight> 112 </Weight>
 </ROW>
</ROWSET>