Exporting XML Documents

Exporting an HTML Document

This example exports an HTML document from a SAS data set. With the HTML format type specified, the XML engine generates HTML tags.

Note:   The HTML type is deprecated beginning in SAS 9.1.3. The HTML type will not be supported in some future release. Equivalent functionality can be achieved by specifying a tagset. See Defining and Using a Customized Tagset to Export an HTML Document.  [cautionend]

The following output shows the SAS data set MYFILES.CLASS to be exported to an HTML document.

SAS Data Set MYFILES.CLASS

                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 exports an HTML document from the SAS data set MYFILES.CLASS:

libname myfiles 'SAS-library'; [1]

libname trans xml 'XML-document' xmltype=html; [2]

data trans.class; [3] 
   set myfiles.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 V9 engine is the default.

  2. The second LIBNAME statement assigns the libref TRANS to the physical location of the file that will store the exported HTML document (complete pathname, filename, and file extension) and specifies the XML engine. The engine option XMLTYPE=HTML produces the HTML tags. By default, metadata-related information is not generated.

  3. The DATA step reads the SAS data set MYFILES.CLASS and writes its content in HTML format to the specified XML document.

Here is the resulting HTML document.

HTML Document Exported from MYFILES.CLASS

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
   <BODY>
      <TABLE border="1" width="100%">
         <TBODY>
            <TR>
               <TD> Alfred </TD>
               <TD> M </TD>
               <TD> 14 </TD>
               <TD> 69 </TD>
               <TD> 112.5 </TD>
            </TR>
            <TR>
               <TD> Alice </TD>
               <TD> F </TD>
               <TD> 13 </TD>
               <TD> 56.5 </TD>
               <TD> 84 </TD>
            </TR>
            .
            .
            .
            <TR>
               <TD> William </TD>
               <TD> M </TD>
               <TD> 15 </TD>
               <TD> 66.5 </TD>
               <TD> 112 </TD>
            </TR>
         </TBODY>
      </TABLE>
   </BODY>
</HTML>

space
Previous Page | Next Page | Top of Page