Skip to content
AgileLogics
7 min read

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 pdf statement and ods 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, and ods powerpoint work the same way.
  • style= changes the look; journal is 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 exclude hides 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), and reg (a fitted line) cover most charts. Several statements in one step overlay on the same axes.
  • group= colors by category; xaxis and yaxis statements set labels and ranges.
  • PROC SGPANEL draws 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.