SAS Institute. The Power to Know

FOCUS AREAS

Return to previous page

Base SAS

Generating an HTML Document

This example generates an output HTML document from a SAS data set. With the HTML format specified, the XML engine generates HTML tags. The following output shows the SAS data set MYFILES.CLASS to be exported to an HTML document:

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

libname myfiles 'SAS-library';

libname trans xml 'external-file' xmltype=html;

proc copy in=myfiles out=trans;
   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 HTML document (complete pathname and file name) and specifies the XML engine. The engine option XMLTYPE=HTML produces the HTML tags. By default, schema-related information is not generated.

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

The resulting HTML document is as follows:

<!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>

To compare the generated output, the following code generates the HTML document with schema-related information by including the option XMLSCHEMA=YES:

libname myfiles 'SAS-library';

libname trans xml 'external-file' xmltype=html xmlschema=yes;

proc copy in=myfiles out=trans;
   select class;
run;

The resulting HTML document is as follows:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
   <BODY>
      <TABLE border="1" width="100%">
         <THEAD>
            <TR>
               <TH> Name </TH>
               <TH> Sex </TH>
               <TH> Age </TH>
               <TH> Height </TH>
               <TH> Weight </TH>
            </TR>
         </THEAD>
         <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>