Understanding and Customizing SAS Output: The Output Delivery System (ODS) |
Identifying Output |
Program output, in the form of output objects, contain both the results of a procedure or DATA step and information about how to format the results. To select an output object for formatting, you need to know which output objects your program creates. To identify the output objects, use the ODS TRACE statement. The simplest form of the ODS TRACE statement is as follows:
ODS TRACE ON|OFF; |
ODS TRACE determines whether to write to the SAS log a record of each output object that a program creates. The ON option writes the trace record to the log, and the OFF option suppresses the writing of the trace record.
The trace record has the following components:
Name | |
Label |
is the label that briefly describes the contents of the output object. |
Template |
is the name of the table definition that ODS used to format the output object. |
Path |
In the ODS SELECT statement in your program, you can refer to an output object by name, label, or path.
The following program executes the UNIVARIATE procedure and writes a trace record to the SAS log.
ods trace on; proc univariate data=sat_scores; var SATscore; class Gender; title1 'Average SAT Scores Entering College Classes, 1972-1998*'; footnote1 '* Recentered Scale for 1987-1995'; run; ods trace off;
The following output shows the results of ODS TRACE. Two sets of output objects are listed because the program uses the class variable Gender to separate male and female results. The path component of the output objects identifies the female (f) and male (m) objects.
403 ods trace on; 404 405 proc univariate data=sat_scores; 406 var SATscore; 407 class Gender; 408 title1 'Average SAT Scores Entering College Classes, 1972-1998*'; 409 footnote1 '* Recentered Scale for 1987-1995'; 410 run; Output Added: ------------- Name: Moments Label: Moments Template: base.univariate.Moments Path: Univariate.SATscore.f.Moments Output Added: ------------- Name: BasicMeasures Label: Basic Measures of Location and Variability Template: base.univariate.Measures Path: Univariate.SATscore.f.BasicMeasures ------------- Output Added: ------------- Name: TestsForLocation Label: Tests For Location Template: base.univariate.Location Path: Univariate.SATscore.f.TestsForLocation ------------- Output Added: ------------- Name: Quantiles Label: Quantiles Template: base.univariate.Quantiles Path: Univariate.SATscore.f.Quantiles ------------- Output Added: ------------- Name: ExtremeObs Label: Extreme Observations Template: base.univariate.ExtObs Path: Univariate.SATscore.f.ExtremeObs ------------- Output Added: ------------- Name: Moments Label: Moments Template: base.univariate.Moments Path: Univariate.SATscore.m.Moments ------------- Output Added: ------------- Name: BasicMeasures Label: Basic Measures of Location and Variability Template: base.univariate.Measures Path: Univariate.SATscore.m.BasicMeasures -------------
Output Added: ------------- Name: TestsForLocation Label: Tests For Location Template: base.univariate.Location Path: Univariate.SATscore.m.TestsForLocation ------------- Output Added: ------------- Name: Quantiles Label: Quantiles Template: base.univariate.Quantiles Path: Univariate.SATscore.m.Quantiles ------------- Output Added: ------------- Name: ExtremeObs Label: Extreme Observations Template: base.univariate.ExtObs Path: Univariate.SATscore.m.ExtremeObs ------------- 411 412 ods trace off;
Selecting and Excluding Program Output |
For each destination, ODS maintains a selection list or an exclusion list. The selection list is a list of output objects that produce formatted output. The exclusion list is a list of output objects for which no output is produced.
You can select and exclude output objects by specifying the destination in an ODS SELECT or ODS EXCLUDE statement. If you do not specify a destination, ODS sends output to all open destinations.
Selection and exclusion lists can be modified and reset at different points in a SAS session, such as at procedure boundaries. If you end each procedure with an explicit QUIT statement, rather than waiting for the next PROC or DATA step to end it for you, the QUIT statement resets the selection list.
To choose one or more output objects and send them to open ODS destinations, use the ODS SELECT statement. The simplest form of the ODS SELECT statement is as follows:
ODS SELECT <ODS-destination> output-object(s); |
The argument ODS-destination identifies the output format, and output-object specifies one or more output objects to add to a selection list.
To exclude one or more output objects from being sent to open destinations, use the ODS EXCLUDE statement. The simplest form of the ODS EXCLUDE statement is as follows:
ODS EXCLUDE <ODS-destination> output-object(s); |
The argument ODS-destination identifies the output format, and output-object specifies one or more output objects to add to an exclusion list.
The following example executes the UNIVARIATE procedure and creates 10 output objects. The ODS SELECT statement uses the name component in the trace records to select only the BasicMeasures and the TestsForLocation output objects. Because the HTML and Printer destinations are open, ODS creates HTML and Printer output from the output objects.
options nodate pageno=1; ods listing close; ods html file='odsselect-body.htm' contents='odsselect-contents.htm' page='odsselect-page.htm' frame='odsselect-frame.htm'; ods printer file='odsprinter-select.ps'; ods select BasicMeasures TestsForLocation; proc univariate data=sat_scores; var SATscore; class Gender; title1 'Average SAT Scores Entering College Classes, 1972-1998*'; footnote1 '* Recentered Scale for 1987-1995'; run; ods html close; ods printer close; ods listing;
The following two displays show the results in Printer format. They show the Basic Statistical Measures and Tests for Location tables based on gender.
ODS SELECT Statement: Printer Format (females)
ODS SELECT Statement: Printer Format (males)
The following two displays show the results in HTML format. They, too, show the Basic Statistical Measures and Tests for Location tables based on gender.
ODS SELECT Statement: HTML Format (females)
ODS SELECT Statement: HTML Format (males)
Creating a SAS Data Set |
ODS enables you to create a SAS data set from an output object. To create a single output data set, use the following form of the ODS OUTPUT statement:
ODS OUTPUT output-object(s)=SAS-data-set; |
The argument output-object specifies one or more output objects to turn into a SAS data set, and SAS-data-set specifies the data set that you want to create.
In the following program, ODS opens the Output destination and creates the SAS data set MYFILE.MEASURES from the output object BasicMeasures. ODS then closes the Output destination.
libname myfile 'SAS-data-library'; ods listing close; 1 ods output BasicMeasures=myfile.measures; 2 proc univariate data=sat_scores; 3 var SATscore; class Gender; run; ods output close; 4 ods listing; 5
The following list corresponds to the numbered items in the preceding program:
The following SAS log shows that the MYFILE.MEASURES data set was created with the ODS OUTPUT statement:
Partial SAS Log: SAS Data Set Creation
404 libname myfile 'SAS-data-library'; NOTE: Libref MYFILE was successfully assigned as follows: Engine: V8 Physical Name: path-name 405 ods listing close; 406 ods output BasicMeasures=myfile.measures; 407 408 proc univariate data=sat_scores; 409 var SATscore; 410 class Gender; 411 run; NOTE: The data set MYFILE.MEASURES has 8 observations and 6 variables.
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.