SAS FAQ
How can I use the SAS Output Delivery System?

Creating an output data set
How to identify output objects
Using object label to create an output data set
Turn the listing output off
Output to an HTML file

SAS introduced the Output Delivery System (ODS) with Version 7, making output much more flexible. We show some examples  using ODS here. We are going to use the data set below for the purpose of demonstration.

OPTIONS nocenter;

DATA hsb25;
  INPUT id female race ses schtype $ prog
        read write math science socst;
DATALINES;
 147 1 1 3 pub 1 47  62  53  53  61
 108 0 1 2 pub 2 34  33  41  36  36
  18 0 3 2 pub 3 50  33  49  44  36
 153 0 1 2 pub 3 39  31  40  39  51
  50 0 2 2 pub 2 50  59  42  53  61
  51 1 2 1 pub 2 42  36  42  31  39
 102 0 1 1 pub 1 52  41  51  53  56
  57 1 1 2 pub 1 71  65  72  66  56
 160 1 1 2 pub 1 55  65  55  50  61
 136 0 1 2 pub 1 65  59  70  63  51
  88 1 1 1 pub 1 68  60  64  69  66
 177 0 1 2 pri 1 55  59  62  58  51
  95 0 1 1 pub 1 73  60  71  61  71
 144 0 1 1 pub 2 60  65  58  61  66
 139 1 1 2 pub 1 68  59  61  55  71
 135 1 1 3 pub 1 63  60  65  54  66
 191 1 1 1 pri 1 47  52  43  48  61
 171 0 1 2 pub 1 60  54  60  55  66
  22 0 3 2 pub 3 42  39  39  56  46
  47 1 2 3 pub 1 47  46  49  33  41
  56 0 1 2 pub 3 55  45  46  58  51
 128 0 1 1 pub 1 39  33  38  47  41
  36 1 2 3 pub 2 44  49  44  35  51
  53 0 2 2 pub 3 34  37  46  39  31
  26 1 4 1 pub 1 60  59  62  61  51
;
RUN;

Let's say we have a data set of student scores and want to conduct a paired t-test on writing score and math score for each program type. For some reason, we want to save the t-values and p-values to a data set for later use. Without ODS, it would not be an easy thing to do since proc ttest does not have an output statement. With ODS it is only one more line of code.

We will sort the data set first by variable prog and use statement ods output Ttests=test_output to create a temporary data set called test_output containing information of t-values and p-values together with degrees of freedom for each t-test conducted.

proc sort data=hsb25;
  by prog;
proc ttest data=hsb25;
  by prog;
  paired write*math;
  ods output Ttests=ttest_output;
run;
proc print data=ttest_output;
run;

The SAS System

Obs    prog    Variable1    Variable2     Difference      tValue      DF     Probt

 1       1       write        math       write - math      -1.57      14    0.1389
 2       2       write        math       write - math       0.66       4    0.5475
 3       3       write        math       write - math      -2.37       4    0.0766

For each SAS procedure, SAS produces a group of ODS output objects. For example, in the above example, Ttests is the name of a such object associated with proc ttest. In order to know what objects are associated with a particular proc, we use ods trace on statement right before the proc and turn the trace off right after it. Let's look at another example using proc reg. The option listing with ods trace on displays the information of an object along with the corresponding output. Below we see three objects (data sets in this case) associated with proc reg when no extra options used. The ANOVA part of the output is stored in a data set called ANOVA. The parameter estimates are stored in ParameterEstimates. Each object has a name, a label and a path along with its template. Once we obtain the name or the label of the object, we can use ods output statement to output it to a dataset as shown in the example above.

ods trace on /listing;
proc reg data=hsb25;
 model write = female math;
run;
quit;
ods trace off;

The REG Procedure
Model: MODEL1
Dependent Variable: write

Output Added:
-------------
Name:       ANOVA
Label:      Analysis of Variance
Template:   Stat.REG.ANOVA
Path:       Reg.MODEL1.Fit.write.ANOVA
-------------


                             Analysis of Variance

                                    Sum of           Mean
Source                   DF        Squares         Square    F Value    Pr > F

Model                     2     2154.11191     1077.05596      19.39    <.0001
Error                    22     1222.04809       55.54764
Corrected Total          24     3376.16000

Output Added:
-------------
Name:       FitStatistics
Label:      Fit Statistics
Template:   Stat.REG.FitStatistics
Path:       Reg.MODEL1.Fit.write.FitStatistics
-------------


Root MSE              7.45303    R-Square     0.6380
Dependent Mean       50.44000    Adj R-Sq     0.6051
Coeff Var            14.77603

Output Added:
-------------
Name:       ParameterEstimates
Label:      Parameter Estimates
Template:   Stat.REG.ParameterEstimates
Path:       Reg.MODEL1.Fit.write.ParameterEstimates
-------------

                        Parameter Estimates

                     Parameter       Standard
Variable     DF       Estimate          Error    t Value    Pr > |t|

Intercept     1        7.07533        7.56161       0.94      0.3596
female        1        5.95697        3.07209       1.94      0.0654
math          1        0.76991        0.14323       5.38      <.0001

Along with the name of an object, we also see the label for the object. We can use the label to create a data set just as using the name.

ods output "Parameter Estimates"=parest;
proc reg data=hsb25;
  model write = female math;
run;
quit;
ods output close;

proc print data=parest;
run;

Obs    Model     Dependent    Variable     DF       Estimate         StdErr     tValue     Probt

 1     MODEL1      write      Intercept     1        7.07533        7.56161       0.94    0.3596
 2     MODEL1      write      female        1        5.95697        3.07209       1.94    0.0654
 3     MODEL1      write      math          1        0.76991        0.14323       5.38    <.0001

Since we can save our output from a proc to a dataset using ODS, we sometimes want to turn the listing output off. We can NOT use noprint option since ODS requires an output object. What we'll do is to use ODS statement here shown as in the example below. It makes sense because listing output is just a form of ODS output. The statement ods listing close eliminates the output to appear in the output window. After the proc reg, we turn back the listing output back so output will appear in the output window again. The

ods listing close;
ods output "Parameter Estimates"=parest;
proc reg data=hsb25;
 model write = female math;
run;
quit;
ods output close;
ods listing;

Let's say that we want to write the output of our proc reg to an HTML file. This can be done very easily using ODS. First we specify the file name we are going to use. Then we point the ods html output to it. At the end we close the ods html output to finish writing to the HTML file. You can view procreg.html created by the following code.

filename myhtml "c:\examples\procreg.html";
ods html body=myhtml;
proc reg data=hsb25;
  model write= female math;
run;
quit;
ods html close;

How to cite this page

Report an error on this page or leave a comment

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.