Previous Page | Next Page

Importing XML Documents

Importing an XML Document Using the GENERIC Markup Type

This example imports the following XML document, which conforms to the physical structure for the GENERIC markup type. For information about the required physical structure, see Understanding the Required Physical Structure for an XML Document to Be Imported Using the GENERIC Markup Type.

<?xml version="1.0" encoding="windows-1252" ?>
<TABLE>
   <CLASS>
      <Name> Alfred </Name>
      <Gender> M </Gender>
      <Age> 14 </Age>
      <Height> 69 </Height>
      <Weight> 112.5 </Weight>
   </CLASS>
   <CLASS>
      <Name> Alice </Name>
      <Gender> F </Gender>
      <Age> 13 </Age>
      <Height> 56.5 </Height>
      <Weight> 84 </Weight>
   </CLASS>
.
.
.
   <CLASS>
      <Name> William </Name>
      <Gender> M </Gender>
      <Age> 15 </Age>
      <Height> 66.5 </Height>
      <Weight> 112 </Weight>
   </CLASS>
</TABLE>

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;

  1. The first LIBNAME statement assigns the libref TRANS to the physical location of the XML document (complete pathname, filename, and file extension) and specifies the XML engine. By default, the XML engine expects GENERIC markup.

  2. The second LIBNAME statement assigns the libref MYFILES to the physical location of the SAS library that will store the resulting SAS data set. The V9 engine is the default.

  3. The DATA step reads the XML document and writes its content in SAS proprietary format.

Issuing the following 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

                           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

Previous Page | Next Page | Top of Page