SAS FAQ
How do I create Statistical Graphs in SAS 9.1.3 without Proc Gplot?

SAS 9 introduces a new way to create statistical graphics using ODS (Output Delivery System). These statistical graphs are created within relevant statistical procedures. Therefore, instead of creating a data set and then calling proc gplot, we can get some of the statistical plots, such as a correlation matrix plot, or a regression diagnostic plot directly. We want to emphasize though that SAS 9.1.3 still claims that this feature is experimental. This may imply future change in syntax or other aspects.

There are two things that one has to do in order for this new feature to work. One is to turn on the html format of output. The other is to turn on the graphics feature of ODS. Some of the procedures require more statement than others. 

This page will show some examples exploring this new feature. The data set that we are going to use here is hsb2.sas7bdat.

There are many different ways of creating scatter matrix plot in SAS, one of the easy way is via proc corr. The option that is required is the plots option in the proc corr statement. Choosing different HTML style will create the same plot with different styles, such as the grayish default style, journal style and statistical style. For more example for creating plots using proc corr, please see the SAS's example page.

ods html; /*turn on html output*/
ods listing close; /*turn off list (regular) output window, optional*/
ods graphics on; /*turn on ods graphics*/

proc corr data = hsb2 plots;
  var write math read science socst;
run;

ods graphics off;
ods html close;
ods listing;
SymMatrixPlot0.gif
ods html style=journal;
ods listing close;
ods graphics on;
proc corr data = hsb2 plots;
  var write math read science socst;
run;
ods graphics off;
ods html close;
ods listing;
SymMatrixPlot2.gif

As in SAS 8, proc reg has the facility of creating many types of plots related to regression. By default, if we turn on the ods graphics facility, we will get a series of regression diagnostics plots shown below. Our next example shows how to unpack the plots so that the plots will be displayed individually.

ods html;
ods listing close;
ods graphics on;
proc reg data = hsb2 ; 
  model write = female math; 
run;
quit;
ods graphics off;
ods html close;
ods listing;

Fit Diagnostics

Residual Plots

ods html style = journal;
ods listing close;
ods graphics on;
*option plots(unpack) will display plots individually;
proc reg data = hsb2 plots(unpack); 
  model write = female math; 
run;
quit;
ods graphics off;
ods html close;
ods listing; 
Residual Histogram
(More plots in between are deleted ...)
Residual Plots

Proc glm creates a couple of different types of plots for ANCOVA and ANOVA.

ods html ;
ods graphics on;
proc glm data = hsb2 ;
  class female ;
  model write =  read*female /solution;
  lsmeans ses;
run;
quit;
ods graphics off;
ods html close;
ANCOVA Plot
ods html style=statistical;
ods graphics on;
proc glm data = hsb2 ;
  class ses ;
  model write =  ses /solution;
run;
quit;
ods graphics off;
ods html close;
Box Plot

Proc logistic can create many diagnostics plots if the influence option is specified for the model statement. One potential problem with using the influence option is that it also creates pages after pages of output, especially when the data set has a lot of observations. One way to avoid to have too much output is to use the ods select statement to select only part of the output of interest. In this case, we are only interested in producing the plots, so we choose influenceplots to be displayed suppressing all the other output. For SAS's example on logistic regression diagnostics, visit their page.

data hsb2;
  set in.hsb2;
  hwrite = (write>=60);
run;
ods html style=statistical;
ods select influenceplots; /*only output the plots*/
ods graphics on ;
proc logistic data = hsb2 descending;
  class ses (ref='1') /param=reference;
  model hwrite =  ses math female /influence;
run;
ods graphics off;
ods html close;
Panel 1
Panel 2
Panel 3
 

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.