• Print  |
  • Feedback  |

FOCUS AREAS

Return to previous page

Base SAS

Moving a SAS Data Set from One Host to Another

This example generates an output XML document on the source host, then translates the XML markup on the target host. The XML engine uses all defaults; for example, the format is GENERIC, which is simple, well-formed XML markup.

The following output shows the SAS data set MYFILES.CLASS to be moved from one host to another:

                                 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 on the source host for the SAS data set MYFILES.CLASS:

libname myfiles 'SAS-library'; [1]   

libname trans xml 'external-file'; [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 in SAS proprietary format. The V8 base engine is the default.

  2. The second LIBNAME statement assigns the libref TRANS to the physical location of the file (complete pathname and file name) that will store the generated XML document, and then specifies the XML engine. By default, the XML engine generates GENERIC format.

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

The resulting XML document is as follows:

<?xml version="1.0" ?>
<TABLE>
   <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>
</TABLE>

After the XML document is generated on the source host, it must be transferred from the source host to the target host. For example, you can use FTP (File Transfer Protocol) to transfer the file.

With the XML document available on the target host, the following SAS program translates the XML markup to SAS proprietary format:

libname trans xml 'external-file'; [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 and file name) that was transferred to the target host, and specifies the XML engine. By default, the XML engine expects GENERIC format.

  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 V8 base engine is the default.

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

Issuing the following code produces a frequency analysis on the data set that was translated from the XML document:
proc freq data=myfiles.class;
run;

                                 The SAS System                                1

                               The FREQ Procedure

                                     WEIGHT

                                             Cumulative    Cumulative
          WEIGHT    Frequency     Percent     Frequency      Percent
          -----------------------------------------------------------
            50.5           1        5.26             1         5.26
            77.0           1        5.26             2        10.53
            83.0           1        5.26             3        15.79
            84.0           2       10.53             5        26.32
            84.5           1        5.26             6        31.58
            85.0           1        5.26             7        36.84
            90.0           1        5.26             8        42.11
            98.0           1        5.26             9        47.37
            99.5           1        5.26            10        52.63
           102.5           2       10.53            12        63.16
           112.0           2       10.53            14        73.68
           112.5           2       10.53            16        84.21
           128.0           1        5.26            17        89.47
           133.0           1        5.26            18        94.74
           150.0           1        5.26            19       100.00

.
.
.