SAS introduced the Output Delivery System (ODS) in version 7 which provides a way of managing your SAS output. This document illustrates how you can use ODS to:
- create SAS data sets from procedure output
- redirect tabular output to HTML, Rich Text Format (RTF), or PostScript formatted files for inclusion in other programs like Internet Explorer, Word, WordPerfect, or Latex.
- select and exclude components of the tabular output
- use templates to customize the appearance of tabular output layout, format, and headers.
SAS has extended the capabilities of ODS in version 9.1 to include graphics for some statistical procedures. Graphics produced through ODS require minimal syntax, unlike graphs produced through SAS/GRAPH. ODS for statistical graphics is documented in A Simple Procedure for Producing Publication-Quality Graphs using SAS.
Creating SAS Data Sets from Procedure Output
SAS procedures have always made the most important statistics available as output data sets (using OUT= options or OUTPUT statements), but with ODS, every number in every table of every procedure can be accessed via a data set.
ODS divides procedure output into components called output objects. Look at the following default output from the TTEST procedure:
Statistics Lower CL Upper CL Lower CL Variable gender N Mean Mean Mean Std Dev Std Dev score f 7 74.504 76.857 79.211 1.6399 2.5448 score m 7 79.804 82.714 85.625 2.028 3.1472 score Diff (1-2) -9.19 -5.857 -2.524 2.0522 2.8619 Statistics Upper CL Variable gender Std Dev Std Err Minimum Maximum score f 5.6039 0.9619 73 80 score m 6.9303 1.1895 78 87 score Diff (1-2) 4.7242 1.5298 T-Tests Variable Method Variances DF t Value Pr > |t| score Pooled Equal 12 -3.83 0.0024 score Satterthwaite Unequal 11.5 -3.83 0.0026 Equality of Variances Variable Method Num DF Den DF F Value Pr > F score Folded F 6 6 1.53 0.6189
ODS defines three output objects in the above output: a "Statistics" table, "T-Tests" table, and "Equality of Variances" table. Any object can be written to a SAS data set once you know ODS's name for the object.
Determining the Names of Output Objects
Use the ODS TRACE statement to determine the names of procedure objects:
ods trace output;
proc ttest;
class gender;
var score;
title 'GOLF SCORES';
run;
ods trace off;
When the trace is turned on (ODS TRACE OUTPUT;), information about the objects, including their names, is written to the log:
Output Added:
-------------
Name: Statistics
Label: Statistics
Template: Stat.TTest.Statistics
Path: Ttest.Statistics
-------------
Output Added:
-------------
Name: TTests
Label: T-Tests
Template: Stat.TTest.TTests
Path: Ttest.TTests
-------------
Output Added:
-------------
Name: Equality
Label: Equality of Variances
Template: Stat.TTest.Equality
Path: Ttest.Equality
The three output objects are called Statistics, Ttests, and Equality.
ODS TRACE OFF; turns off the trace. (No RUN statement is needed.)
Redirecting the Output
Once you know the name of the object you want to make a SAS data set from, use the ODS OUTPUT statement to save the results. The ODS OUPUT statement can be placed anywhere before the RUN statement in the procedure step. For example, to save the Statistics object:
proc ttest;
class gender;
var score;
title 'GOLF SCORES';
ods output Statistics = tstats;
run;
Below is a listing of the fourteen variables and three observations that got written to the TSTATS data set:
Lower Upper Lower UMPULower Variable Class N CLMean Mean CLMean CLStdDev CLStdDev score f 7 74.504 76.857 79.211 1.6399 1.5634 score m 7 79.804 82.714 85.625 2.028 1.9335 score Diff (1-2) _ -9.19 -5.857 -2.524 2.0522 2.0019 UMPUUpper Upper StdDev CLStdDev CLStdDev StdErr Minimum Maximum 2.5448 5.2219 5.6039 0.9619 73 80 3.1472 6.4579 6.9303 1.1895 78 87 2.8619 4.5727 4.7242 1.5298 _ _
Redirecting Output to HTML, RTF, or PostScript Files
SAS data sets are not the only place you can redirect output to. You can also redirect output to RTF, HTML, or PostScript formatted files. For example, to redirect the TTEST procedure's output in the example above to an RTF file, add the following two ODS statements to your program:
ods rtf file="tstats.rtf";
proc ttest;
class gender;
var score;
title 'GOLF SCORES';
run;
ods rtf close;
You could then insert the file tstats.rtf into a WORD or WORDPERFECT document and have nicely formatted tables.
To redirect the output to an HTML file, use the ODS HTML statement:
ods html body="tstats.htm";
proc ttest;
class gender;
var score;
title 'GOLF SCORES';
run;
ods html close;
You could then view the output from a browser like Internet Explorer or Netscape.
To create high-resolution printer output, use ODS PRINTER to redirect the output to a PostScript file:
ods printer file="tstats.ps";
proc ttest;
class gender;
var score;
title 'GOLF SCORES';
run;
ods printer close;
Use the Linux lpr command to print the file.
Selecting and Excluding Components of the Output
You can also use ODS to control which output objects you want included or excluded from your output. For example, to request only the Statistics object in your output:
ods select Statistics;
ods html body="tstats.htm";
To exclude the Statistics object from the output:
ods exclude Statistics;
ods rtf file="tstats.rtf";
You can also use the ODS SELECT and EXCLUDE statements to control which tables you want displayed in your default listing (.lst file):
ods listing;
ods exclude Statistics;
proc ttest;
class gender;
var score;
title 'GOLF SCORES';
run;
Note that the LISTING destination is open by default so the only time you need to include an ODS LISTING statement is when you have used another destination like RTF or HTML previously in the program.
To summarize what has been illustrated so far, there are currently five destinations you can specify for your procedure output:
LISTING the default; traditional .lst file
OUTPUT SAS data set
HTML html file
RTF rtf file for inclusion in Word or WordPerfect
PRINTER PostScript file for high resolution output
and you use an ODS SELECT or EXCLUDE statement to control which parts of the procedural output you want.
Customizing The Appearance of Your SAS Output
With ODS you can change the appearance of most of your SAS output. You can reorder columns, change the style of the output including justification, cell formats, colors, fonts, etc. You can apply these changes to the entire SAS output or just to a particular output object.
SAS uses templates to describe what a particular piece of output is supposed to look like by default. The TEMPLATE procedure enables you to create and edit templates. The TEMPLATE procedure can get complicated very quickly. In this section, only a very simple example is provided. For more detailed information, please refer to the on-line manual at http://support.sas.com/documentation/onlinedoc/91pdf/sasdoc_913/base_ods_9268.pdf.
In the example below, the output for the means values in the Statistics table of the TTEST procedure is reformatted to display with only one significant digit after the decimal point. By default, three significant digits are displayed. First, the PROC TEMPLATE step is run to define the new template. Second, the TTEST procedure is run redirecting the output to a SAS data set. Third, the reformatted output is displayed using a DATA step:
proc template;
edit Stat.TTest.Statistics as test;
edit mean; format=8.1; end;
end;
run;
ods listing close;
ods output statistics=tstats;
proc ttest;
class gender;
var score;
title 'GOLF SCORES';
run;
ods listing;
data _null_;
set tstats;
file print ods=(template='test');
put _ODS_;
run;
Notes:
- The first EDIT statement in PROC TEMPLATE is where you name the template you want to modify. The ODS TRACE output (refer to p. 2) provides the name of the template for each object.
- The second edit statement specifies that the means in the Statistics table should be formatted with a width of 8 and 1 digit to the right of the decimal point.
- The FILE statement in the DATA step tells SAS to print the results to the SAS output file (.lst file) using the "test" template created above in the PROC TEMPLATE call.
- The PUT statement tells SAS to write the output using ODS.
You can already see how complicated things get just for this simple example. Again, if you need to customize output, you should refer to the complete documentation on ODS.
Last Revised: 3/19/2007