Chapter 19: Introducing the Output Delivery System

19.1  Introduction

19.2  Sending SAS Output to an HTML File

19.3  Creating a Table of Contents

19.4  Selecting a Different HTML Style

19.5  Choosing Other ODS Destinations

19.6  Selecting or Excluding Portions of SAS Output

19.7  Sending Output to a SAS Data Set

19.8  Problems

 

19.1  Introduction

The Output Delivery System (abbreviated ODS) allows you to send SAS output to a variety of destinations, such as HTML, PDF, RTF, and SAS data sets.

Not only can you send your SAS output to all of these formats, you can, if you are brave enough, customize the output’s fonts, colors, size, and layout. Finally, you can now capture virtually every piece of SAS output to a SAS data set for further processing.

19.2  Sending SAS Output to an HTML File

Beginning in SAS 9.3 the default ODS Destination for SAS output is HTML. If you don't need your output in a file, you don't need to submit any ODS statements unless you want to capture procedure output to a SAS data set.

As an example, suppose you want to send the output of PROC PRINT and PROC MEANS to an HTML file. It takes only two SAS statement to do this, as shown next:

 

Program 19.1: Sending SAS Output to an HTML File

  ods html path='C:ookslearing'

      file='Sample.html';

  title "Listing of Test_Scores";

  proc print data=Learn.Test_Scores;

     title2 "Sample of HTML Output - all defaults";

     id ID;

     var Score1-Score3;

  run;

  title "Descriptive Statistics";

  proc means data=Learn.Test_Scores n nmiss mean min max maxdec=2;

     var Score1-Score3;

  run;

  ods html close;

All that is required is to place an ODS HTML statement before the procedures whose output you want to capture and an ODS HTML CLOSE statement at the end. You specify a PATH= and a FILE= option on the HTML statement. The HTML extension (or HTM for some environments) is not needed by SAS, but it allows the operating system to recognize that the file contains HTML tags and to open it with the appropriate browser.

The HTML output is shown here:

Figure 19.1: HTML File Created by Program 19.1

Figure 19.1: HTML File Created by Program 19.1

If you are using the SAS windowing system and you have chosen the option of producing listing files (Tools Options Preferences Results tab (Check LISTING Box), when you run Program 19.1, SAS will produce a listing file in addition to the HTML file on your disk drive.

19.3  Creating a Table of Contents

If your HTML output is large, you may elect to produce a table of contents along with the normal HTML output. Remember that HTML is primarily intended to be viewed with a web browser, not printed. A table of contents embeds links to each separate part of the output, allowing users to click on a link and go directly to different parts of the output.

To create a table of contents, you need to specify three output files:

        A main file that contains the procedure output

        A table of contents file

        A frame file to display the other two

Here is an example, using the same procedures as Program 19.1:

Program 19.2: Creating a Table of Contents for HTML Output

  ods html body = 'Body_Sample.html'

           contents = 'Contents_Sample.html'

           frame = 'Frame_Sample.html'

           path = 'c:ookslearning';

  title "Using ODS to Create a Table of Contents";

  proc print data=Learn.Test_Scores;

     id ID;

     var Name Score1-Score3;

  run;

  title "Descriptive Statistics";

  proc means data=Learn.Test_Scores n mean min max;

     var Score1-Score3;

  run;

  ods html close;

The four keywords are BODY=, CONTENTS=, FRAME= and PATH=.

You can name the three files anything you like—the names do not need to include the words body, contents, or frame as in this example. If you are creating a web page from these files, you need to provide a link to the FRAME file. A display of the file Contents_Sample.html is shown next.

Figure 19.2: The Contents_Sample.html File

Figure 19.2: The Contents_Sample.html File

If you click on the two links in this file, you will see the PROC PRINT and PROC MEANS output.

19.4  Selecting a Different HTML Style

Although you can customize every aspect of the HTML output, it takes time and effort. There are a number of built-in styles that change the appearance of the output without any work on your part. The default style is called HTMLBLUE.

One way to see a list of styles, if you are in a windowing environment, is to select Tools Options Preferences and then select the Results tab. You will see a long list of built-in styles that you can choose from. For example, if you want black and white output, you could choose the Journal style, like this:

Program 19.3: Choosing a Style for HTML Output

  ods html path = 'c:ookslearning'

           file = 'Journal_Example.html'

                  style=Journal;

  title "Listing of Test_Scores";

  proc print data=Learn.Test_Scores;

     id ID;

     var Name Score1-Score3;

  run;

  ods html close;

The resulting output follows:

Figure 19.3: Output Using the Journal Style

Figure 19.3: Output Using the Journal Style

This style does not contain any shading and, as the name implies, is suitable for printing journal-style tables.

19.5  Choosing Other ODS Destinations

You can create RTF (rich text format) or PDF (portable document format) files, which are both readable with Adobe Reader, in the same manner as HTML output. Just substitute the keywords RTF or PDF for HTML in the statements in Program 19.1 and change the file extensions to RTF or PDF, respectively.

Besides providing a better appearance, using RTF or PDF files allows users of software other than SAS to see well-formatted SAS output without having SAS fonts on their machines. RTF is a somewhat universal format that can be incorporated into a Microsoft Office Word document directly. Have you ever seen what a SAS listing file looks like when it is displayed in a font other than a SAS font? Take a look at output from PROC FREQ, which is displayed in Word with a Courier font (it looks even worse when printed with a proportional font such as Arial or Times Roman):

Figure 19.4: Opening a SAS Listing File in Microsoft Notebook

Figure 19.4: Opening a SAS Listing File in Microsoft Notebook

This output is a strong argument for using RTF or PDF output destinations.

19.6  Selecting or Excluding Portions of SAS Output

You can use an ODS SELECT or ODS EXCLUDE statement before a SAS procedure to control which portions of the output you want.

Suppose you want to use PROC UNIVARIATE to list the five highest and five lowest values of a variable. This is a normal part of the output from PROC UNIVARIATE, but you also get several pages of additional output as well. Program 19.4 uses an ODS SELECT statement to restrict the output.

 

Program 19.4: Using an ODS SELECT Statement to Restrict PROC UNIVARIATE Output

  ods select extremeobs;

  title "Extreme Values of RBC";

  proc Univariate data=Learn.Blood;

     id Subject;

     var RBC;

  run;

When you run this program, the only output is as follows:

Figure 19.5: Output from Program 19.4

Figure 19.5: Output from Program 19.4

This seems simple enough, but how do you determine the name of the output objects (in this case, EXTREMEOBS)? One way is to run the procedure sandwiched between ODS TRACE ON and ODS TRACE OFF statements, like this:

Program 19.5: Using the ODS TRACE Statement to Identify Output Objects

  ods trace on;

  title "Extreme Values of RBC";

  proc Univariate data=Learn.Blood;

     id Subject;

     var RBC;

  run;

  ods trace off;

 

When you run the procedure, the names of the output objects appear in the SAS log as shown next (only selected portions are shown):

Figure 19.6: SAS Log Showing ODS Output Objects

Figure 19.6: SAS Log Showing ODS Output Objects

One way to figure out the correspondence between output objects and portions of the output is to look through the output listing and the list of objects in the SAS log and make an educated guess. It’s usually quite obvious which object goes with each portion of output. If you use TRACE ON/LISTING, the information on each output object is placed in the Output window, along with the listing. This is yet another way to know which output object names go with each portion of the output.

For a more systematic approach, look at the Results window in the SAS windowing environment and notice the labels in the list. For example, the following display results from running Program 19.5:

Figure 19.7: The Results Window in the SAS Windowing Environment

Figure 19.7: The Results Window in the SAS Windowing Environment

If you then right-click on any one of these labels, you will see more information, including the names of all the output objects.

Below is a screen shot taken after right-clicking on Extreme Observation and selecting Preferences:

Figure 19.8: Properties of Extreme Observations

Figure 19.8: Properties of Extreme Observations

You see here that the name of this output object is ExtremeObs.

As an alternative to using the object name in the ODS SELECT statement, you can also select objects by using the labels instead of the object names. For example, you can use the following:

ods select "Extreme Observations";

in place of this statement:

ods select ExtremeObs;

If you use the label, be sure to place it in single or double quotes.

You can include a list of output objects following the ODS SELECT statement (separated by spaces). If you want to select most of the output objects from a particular procedure, it might be easier to use an ODS EXCLUDE statement to exclude the ones you don't want.

Remember that ODS SELECT or EXCLUDE statements only operate on the procedure that follows. If you want the selections to remain for other procedures, you can use the PERSIST option, like this:

ods select ExtremeObs(persist);

19.7  Sending Output to a SAS Data Set

One of the possible ODS output destinations is a SAS data set. This feature of ODS allows you to capture just about any value computed by a procedure and use it in further calculations or a customized report. Prior to the development of ODS, PROC PRINTTO was used to capture SAS output from a procedure and use it as input to a DATA step.

Many procedures already provide you with the ability to capture information in a SAS data set with an OUT= option, usually in an OUTPUT statement. Using ODS to capture output is more general—it lets you capture any value you want. Suppose you want to run a statistical procedure called a t-test. This statistical test produces a t-value and a p-value (the significance of the result). These two values are not available in an output data set from PROC TTEST, but you can use ODS to place these values into a SAS data set. If you are not familiar with PROC TTEST, it should still be clear how to capture SAS procedure output into SAS data sets. Here is a program to capture a portion of the t-test output to a data set:

Program 19.6: Using ODS to Send Procedure Output to a SAS Data Set

  ods listing close;

  ods output ttests=T_Test_Data;

  proc ttest data=Learn.Blood;

     class Gender;

     var RBC WBC Chol;

  run;

  ods listing;

  title "Listing of T_Test_Data";

  proc print data=T_Test_Data;

  run;

This program first closes the listing destination so that output is not sent to the Output window.

Note: You cannot use a NOPRINT option on procedures that allow it. If you do, the values will not be available to be sent to alternate ODS destinations.

Next, the ODS OUTPUT statement is used to send the output to a data set. The keyword to the left of the equal sign is the name of an output object produced by PROC TTEST.

Following the equal sign is the name of the data set you want to create. You then run the procedure in the usual way. The first time you do this, you should run a PROC PRINT to determine the structure of the output data set.

 

Here is the output:

Figure 19.9: Output from Program 19.6

Figure 19.9: Output from Program 19.6

The structure of these output data sets can be complicated. In this instance, you know that PROC TTEST produces two t-values, one under the assumption of equal variance and the other under the assumption of unequal variance. What can you do with this data set?

Sending computed values to a data set enables you to perform additional analyses on them. Also, you might want to present the output from a SAS procedure differently from the way SAS presents it. As an example, suppose you want to see a simple report showing the t- and p-values from your t-test, rather than the more complicated output from PROC TTEST. Once you know the structure of the output data set created by ODS, you can proceed like this:

Program 19.7: Using an Output Data Set to Create a Simplified Report

  title "T-Test Results – Using Equal Variance Method";

  proc report data=T_Test_Data;

     where Variances = "Equal";

     columns Variable tValue ProbT;

     define Variable / width="8";

     define tValue / display "T-Value" width="7" format=7.2;

     define ProbT / display "P-Value" width="7" format=7.5;

  run;

Inspection of data set T_Test_Data shows that there are separate observations for the two variance assumptions. You can use a WHERE statement to select statistics using the equal variance assumption. The result of the PROC REPORT is a simple listing showing the variable name along with the t- and p-values. Here it is:

Figure 19.10: Output from Program 19.7

Figure 19.10: Output from Program 19.7

This chapter has just touched the surface of the capabilities of the Output Delivery System. However, by routing your output to destinations such as HTML or PDF files or by using ODS SELECT statements, you can create output for web pages or company reports that look much more impressive than a standard listing report.

19.8  Problems

Solutions to odd-numbered problems are located at the back of this book. Solutions to all problems are available to professors. If you are a professor, visit the book’s companion website at support.sas.com/cody for information about how to obtain the solutions to all problems.

1.       Run the following program, sending the output to an HTML file. See Chapter 16, Problem 2, for the note about creating formats for this data set.

  title "Sending Output to an HTML File";

  proc print data=Learn.College(obs=8) noobs;

  run;

  proc means data=learn.college n mean maxdec=2;

     var GPA ClassRank;

  run;

2.       Run the same two procedures shown in Problem 1, except create a contents file, a body file, and a frame file.

3.       Run the same two procedures as shown in Problem 1, except use the JOURNAL (or FANCYPRINTER) style instead of the default style.

4.       Send the results of a PROC PRINT on the data set Survey to an RTF file.

5.       Run PROC UNIVARIATE on the variables Age and Salary from the Survey data set. Use the TRACE ON/TRACE OFF statements to display the names of the output objects created by this procedure. Once you have done this, run PROC UNIVARIATE again, selecting only the output object that shows Quantiles.

6.       Run the same PROC UNIVARIATE as in Problem 5. Issue two ODS statements: one to select the MOMENTS output object and the other to send this output to a SAS data set. Run PROC PRINT to see a listing of this data set.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset