Previous Page | Next Page

Understanding and Customizing SAS Output: The Output Delivery System (ODS)

Creating Formatted Output


Creating HTML Output for a Web Browser


Understanding the Four Types of HTML Output Files

When you use the ODS HTML statement, you can create output that is formatted in HTML. You can browse the output files with Internet Explorer, Netscape, or any other browser that fully supports the HTML 3.2 tag set.

The ODS HTML statement can create four types of HTML files:

The body file is required with all ODS HTML output. If you do not want to link to your output, then creating a table of contents, a table of pages, and a frame file is not necessary.


Creating HTML Output: The Simplest Case

To produce the simplest kind of HTML output, the only file you need to create is a body file.

The following example executes the MEANS procedure and creates an HTML body file and the default Listing file. These files contain summary statistics for the average SAT scores of entering first-year college students. The output is grouped by the CLASS variables Test and Gender.

options pageno=1 nodate pagesize=30 linesize=78;
ods html file='summary-results.htm'; 1 

proc means data=sat_scores fw=8; 2 
   var SATscore;
   class Test Gender;
   title1 'Average SAT Scores Entering College Classes, 1972-1998*';
   footnote1 '* Recentered Scale for 1987-1995';
run;

ods html close; 3 

The following list corresponds to the numbered items in the preceding program:

[1] The ODS HTML statement opens the HTML destination and creates the body file SUMMARY-RESULTS.HTM.

[2] The MEANS procedure produces summary statistics for the average SAT scores of entering first-year college students. The output is grouped by the CLASS variables Test and Gender.

[3] The ODS HTML CLOSE statement closes the HTML destination to make output available for viewing.

The following output shows the results in HTML format:

ODS Output: HTML Format

[ODS Output: HTML Format]

The following output shows the results in the Listing format:

ODS Output: Listing Format

            Average SAT Scores Entering College Classes, 1972-1998*            1

                              The MEANS Procedure

                         Analysis Variable : SATscore 
 
                          N
  Test       Gender     Obs     N       Mean    Std Dev    Minimum    Maximum
  ---------------------------------------------------------------------------
  Math       f           27    27      481.8     7.0057      473.0      496.0

             m           27    27      521.6     4.3175      515.0      531.0

  Verbal     f           27    27      503.0     8.2671      495.0      529.0

             m           27    27      510.5     6.7218      501.0      531.0
  ---------------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
                        * Recentered Scale for 1987-1995

Creating HTML Output: Linking Results with a Table of Contents

The ODS HTML destination enables you to link to your results from a table of contents and a table of pages. To do this, you need to create the following HTML files: a body file, a frame file, a table of contents, and a table of pages (see Understanding the Four Types of HTML Output Files). When you view the frame file and select a link in the table of contents or the table of pages, the HTML table that contains the selected part of the procedure results appears at the top of your browser.

The following example creates multiple pages of output from the UNIVARIATE procedure. You can access specific output results (tables) from links in the table of contents or the table of pages. The results contain statistics for the average SAT scores of entering first-year college classes. The output is grouped by the value of Gender in the CLASS statement and by the value of Test in the BY statement.

proc sort data=sat_scores out=sorted_scores;
   by Test;
run;

options pageno=1 nodate;

ods listing close; 1 
ods html file='odshtml-body.htm' 2 
         contents='odshtml-contents.htm' 
         page='odshtml-page.htm' 
         frame='odshtml-frame.htm'; 

proc univariate data=sorted_scores; 3 
   var SATscore;
   class Gender;
   by Test;
   title1 'Average SAT Scores Entering College Classes, 1972-1998*';
   footnote1 '* Recentered Scale for 1987-1995';
run;

ods html close; 4 
ods listing; 5 

The following list corresponds to the numbered items in the preceding program:

[1] By default, the Listing destination is open. To conserve resources, the ODS LISTING CLOSE statement closes this destination.

[2] The ODS HTML statement opens the HTML destination and creates four types of files:

  • the body file (created with the FILE= option), which contains the formatted data

  • the contents file, which is a table of contents with links to items in the body file

  • the page file, which is a table of pages with links to items in the body file

  • the frame file, which displays the table of contents, the table of pages, and the body file

[3] The UNIVARIATE procedure produces statistics for the average SAT scores of entering first-year college students. The output is grouped by the value of Gender in the CLASS statement and the value of Test in the BY statement.

[4] The ODS HTML CLOSE statement closes the HTML destination to make output available for viewing.

[5] The ODS LISTING statement reopens the Listing destination so that the next program that you run can produce Listing output.

The following SAS log shows that four HTML files are created with the ODS HTML statement:

Partial SAS Log: HTML File Creation

489  ods listing close;
490  ods html file='odshtml-body.htm'
491           contents='odshtml-contents.htm'
492           page='odshtml-page.htm'
493           frame='odshtml-frame.htm';
NOTE: Writing HTML Body file: odshtml-body.htm
NOTE: Writing HTML Contents file: odshtml-contents.htm
NOTE: Writing HTML Pages file: odshtml-page.htm
NOTE: Writing HTML Frames file: odshtml-frame.htm
494  
495  proc univariate data=sorted_scores;
496    var SATscore;
497    class Gender;
498     by Test;
499    title1 'Average SAT Scores Entering College Classes, 1972-1998*';
500    footnote1 '* Recentered Scale for 1987-1995';
501  run;

The following output shows the frame file, which displays the table of contents (upper left side), the table of pages (lower left side), and the body file (right side).

View of the HTML Frame File

[View of the HTML Frame File]

Both the Table of Contents and the Table of Pages contain links to the results in the body file. If you click on a link in the Table of Contents or the Table of Pages, SAS displays the corresponding results at the top of the browser.


Creating PostScript Output for a High-Resolution Printer

You can create output that is formatted for a high-resolution printer if you open the Printer destination. Before you can access the file, however, you must close the Printer destination.

The following example executes the MEANS procedure and creates a PostScript file which contains summary statistics for the average SAT scores of entering first-year college students. The output is grouped by the value of Gender in the CLASS statement and the value of Test in the BY statement.

proc sort data=sat_scores out=sorted_scores;
   by Test;
run;

options pageno=1 nodate;

ods listing close; 1 
ods printer ps file='odsprinter_output.ps'; 2 

proc means data=sorted_scores fw=8; 3 
   var SATscore;
   class Gender ;
   by Test;
   title1 'Average SAT Scores Entering College Classes, 1972-1998*';
   footnote1 '* Recentered Scale for 1987-1995';
run;

ods printer close; 4 
ods listing; 5 

The following list corresponds to the numbered items in the preceding program:

[1] By default, the Listing destination is open. To conserve resources, the program uses the ODS LISTING CLOSE statement to close this destination.

[2] The ODS PRINTER statement opens the Printer destination and specifies the file to write to. The PS (PostScript) option ensures that you create a generic PostScript file. If this option is missing, ODS produces output for your current printer, if possible.

[3] The MEANS procedure produces summary statistics for the average SAT scores of entering first-year college students. The output is grouped by the value of Gender in the CLASS statement and the value of Test in the BY statement.

[4] The ODS PRINTER CLOSE statement closes the Printer destination to make output available for printing.

[5] The ODS LISTING statement reopens the Listing destination so that the next program that you run can produce Listing output.

The following output shows the results:

ODS Output: PostScript Format

[ODS Output: PostScript Format]


Creating RTF Output for Microsoft Word

You can create output that is formatted for use with Microsoft Word if you open the RTF destination. Before you can access the file, you must close the RTF destination.

The following example executes the UNIVARIATE procedure and creates an RTF file that contains summary statistics for the average SAT scores of entering first-year college students. The output is grouped by the CLASS variable Gender.

ods listing close; 1 
ods rtf file='odsrtf_output.rtf'; 2 

proc univariate data=sat_scores; 3  
   var SATscore;
   class Gender;
   title1 'Average SAT Scores Entering College Classes, 1972-1998*';
   footnote1 '* Recentered Scale for 1987-1995';
run;

ods rtf close; 4 
ods listing; 5 

The following list corresponds to the numbered items in the preceding program:

[1] By default, the Listing destination is open. To conserve resources, the ODS LISTING CLOSE statement closes this destination.

[2] The ODS RTF statement opens the RTF destination and specifies the file to write to.

[3] The UNIVARIATE procedure produces summary statistics for the average SAT scores of entering first-year college students. The output is grouped by the CLASS variable Gender.

[4] The ODS RTF CLOSE statement closes the RTF destination to make output available.

[5] The ODS LISTING statement reopens the Listing destination so that the next program that you run can produce Listing output.

The following output shows the first page of the RTF output:

ODS Output: RTF Format

[ODS Output: RTF Format]

Previous Page | Next Page | Top of Page