Using the Output Delivery System

Example 20.1 Creating HTML Output with ODS

This example demonstrates how you can use the ODS HTML statement to display your output in HTML. The following statements create the data set Scores, which contains the golf scores of boys and girls in a physical education class:

title 'Comparing Group Means';

data Scores;
   input Gender $ Score @@;
   datalines;
f 75  f 76  f 80  f 77  f 80  f 77  f 73
m 82  m 80  m 85  m 85  m 78  m 87  m 82
;

The TTEST procedure is used to compare the scores. The ODS HTML statement specifies the name of the file to contain the HTML output. The following statements create the HTML file ttest.htm:

ods html body='ttest.htm' style=HTMLBlue;

proc ttest;
   class Gender;
   var Score;
run;

ods html close;

In many cases, the LISTING destination is open by default. See the section Output Defaults for more information about default destinations. When the LISTING destination is open, the LISTING destination receives all output generated during your SAS session. In this example, the ODS HTML statement also opens the HTML destination, and both destinations receive the generated output. If you are in the SAS windowing environment and are using the internal browser, you do not need to close the HTML destination before viewing your output. However, when you write to an HTML file, you must specify the following statement before you can view your output in an external browser:

ods html close;

If you do not close the HTML destination, your HTML file might contain no output or incomplete output, or you might experience other unexpected results.

The following statements use ODS to display the output in HTML with a table of contents:

ods _all_ close;
ods html body='ttest.htm' contents='ttestc.htm' frame='ttestf.htm'
         style=HTMLBlue;
ods graphics on;

proc ttest;
   class Gender;
   var Score;
run;

ods html close;
ods listing;

The ODS _ALL_ CLOSE statement closes all open destinations. The ODS HTML statement specifies three files and the HTMLBLUE style of output. The BODY= option specifies the file that contains the SAS output. The CONTENTS= option specifies the file that contains the table of contents. The FRAME= option specifies the file that displays both the table of contents and the output. You can open the FRAME= file (ttestf.htm) in your browser to view the table of contents together with the generated output (see Output 20.1.1). By default, the HTML files are generated in your current working directory. You can instead specify a path, such as frame=’html/ttestf.htm’, to store a file in a subdirectory.

If you specify the ODS HTML statement with only the BODY= argument, no table of contents is created. The table of contents contains the descriptive label for each output object produced in the PROC TTEST step. You can select any label in the table of contents, and the corresponding output is displayed on the right side of the browser window.

The ODS GRAPHICS ON statement enables ODS Graphics, which creates the graph displayed in Output 20.1.1. For general information about ODS Graphics, see Chapter 21: Statistical Graphics Using ODS.

Output 20.1.1: HTML Output with a Table of Contents and a Frame

HTML Output with a Table of Contents and a Frame