ODS: Output Delivery and Graphs
Prerequisites: Macro programs
Every procedure sends its tables and graphs through the Output Delivery System (ODS). ODS decides where they go — HTML in SAS Studio by default — and lets you capture them as data.
Reports to files
/* illustrative: use your own home folder path */
ods pdf file='/home/u12345678/class_report.pdf' style=journal;
title 'Class Summary';
proc means data=sashelp.class maxdec=1;
class sex;
var height weight;
run;
proc sgplot data=sashelp.class;
scatter x=height y=weight / group=sex;
run;
ods pdf close;
title;
- Everything between the
ods pdfstatement andods pdf close;goes into one PDF — tables and graphs together. ods rtf(Word),ods excel(a native.xlsx, one sheet per table by default),ods html5, andods powerpointwork the same way.style=changes the look;journalis a clean black-and-white style.- Several destinations can be open at once.
Finding and choosing tables
Each procedure produces named output objects. ODS TRACE lists them
in the log:
ods trace on;
proc means data=sashelp.class;
var height;
run;
ods trace off;
Log (abridged):
Output Added:
-------------
Name: Summary
Label: Summary statistics
Template: base.summary
Path: Means.Summary
-------------
ods select ParameterEstimates;before a procedure shows only that table;ods excludehides tables.ods output Summary=stats;saves the table as a data set — the most reliable way to capture any number a procedure prints.
Graphs with PROC SGPLOT
proc sgplot data=sashelp.class;
histogram weight;
density weight;
run;
proc sgplot data=sashelp.class;
vbar age / response=weight stat=mean;
run;
proc sgplot data=sashelp.class;
reg x=height y=weight / clm;
run;
scatter,series(lines),histogram,density,vbar/hbar,vbox(box plots), andreg(a fitted line) cover most charts. Several statements in one step overlay on the same axes.group=colors by category;xaxisandyaxisstatements set labels and ranges.PROC SGPANELdraws a grid of panels, one per group.- Statistical procedures also draw their own diagnostic plots when
ods graphics on;is in effect (the default in SAS Studio).
Practice
Save the "Summary" table of PROC MEANS for weight by sex into a data set
with ODS OUTPUT, without printing anything, and print the new data set.
Show solution
ods exclude all;
ods output Summary=wt_stats;
proc means data=sashelp.class mean;
class sex;
var weight;
run;
ods exclude none;
proc print data=wt_stats noobs;
var sex nobs weight_mean;
format weight_mean 6.2;
run;
Sex NObs Weight_Mean
F 9 90.11
M 10 108.95
ods exclude all; suppresses display, but the output objects are still
created, so ODS OUTPUT can capture them. ods exclude none; restores
normal output.