Lesson 44:  ODS

<<Previous|Contents|Next>>

Video:  Traffic Lighting
Use ODS to send output to different destinations, e.g.:
ods listing close;
ods html file="c:\stats\manpresults.xls" style=minimal;
proc reg data=s.manp;
  model y=x1-x7;
quit;
ods html close;
ods listing;
This ods command creates an external file with the given path and filename.
The "ods html close" command is important here.  Any time you want to create a file, whether html, pdf, or anything else, the file on the disk is not closed until the ods close command is issued.  This has two results, 1.  You cannot open it with an outside program, and 2.  If more output is generated, say by running the procedure again, the new output will be added to the file.

SAS will not overwrite these files if they are open in either the results viewer or Excel (externally).  So you must remember to close the document in Excel or in the Results Viewer before running the program again.

The results viewer opens this like an Excel file because of the xls extension, and the file can be double-clicked and opened in Excel directly. It is actually an html file, though.  Excel knows how to open html files.  It will not become an Excel file unless you go "Save As" and save it in Excel format.

You can apply different styles to change the appearance of the output.  Use the "minimal" style to keep the formatting simple for later modification in Excel.  There are many styles available, although not all are useful for html.  Refer to the lesson on ODS or ODS documentation for more information about styles.

Use ODS select to choose which tables to print.  Use ODS output to send an output table (or object) to a SAS data set.

ods listing close;
ods html file="c:\stats\manpresults.xls" style=minimal;
proc reg data=s.manp;
  model y=x1-x7;
  ods select parameterestimates;
  ods output parameterestimates=manpresults;
quit;
ods html close;
ods listing;

Now you can use proc print to print it, using only the desired variables, and sending the output to html or an excel file.

ods listing close;
ods html file="c:\stats\manpresults.xls" style=minimal;
proc print data=s.manpresults;
  var variable estimate stderr tvalue probt;
run;
ods html close;
ods listing;

You can format titles, such as:

title font=times color=red bcolor=yellow height=6 "Parameter Estimates Table";

You can also use proc report instead of proc print.

ods listing close;
ods html file="c:\stats\manpresults.xls" style=minimal;
proc report data=manpresults nowindows split="/";
columns variable estimate stderr tvalue probt;
define variable/display "Variable/Name";
define estimate/display "Parameter/Estimate";
define stderr/display "Standard/Error";
define tvalue/display "Test/Statistic" width=9;
define probt/display "P-/Value";
run;
ods html close;
ods listing;

Proc report allows greater control of the output, and in particular will allow us to do "Traffic Lighting."  In html the column headings won't automatically split like they do in the output window, so a split character can be added to accomplish that.

Use "traffic lighting" to change colors of different p-values or highlight whole rows.  In the define statement for a variable, you can put a style command like this:

   define probt/display "P-/Value" style=column[foreground=red
     background=yellow font_weight=bold];

This will change the appearance of a whole column. However we would like the change to apply only to certain rows.  In order to do this, we introduce another feature of proc report, the compute block.  But even before that, we need to define a format, since the p-value is a continuous variable.  We want to define the ranges that our traffic lighting will affect.

proc format;
value pvalcolor
  low-<.05=green
  .05-<.1=blue
  other=red;
run;

Now use the format by putting it in place of the color in the define statement.  We also take out the background color here.  You could make another format to assign contrasting colors to the background.

   define probt/display "P-/Value" style=column[foreground=pvalcolor.
     font_weight=bold];

<<Previous|Contents|Next>>

Exercise:

Copyright reserved by Dr.  Dwight Galster, 2009.  Please request permission for reprints (other than for personal use) from dgalster@aol.com  .  "SAS" is a registered trade name of SAS Institute, Cary North Carolina.  All other trade names mentioned are the property of their respective owners.  This document is a work in progress and comments are welcome.  Please send an email if you find it useful or if your site links to it.