SAS Institute. The Power to Know

FOCUS AREAS

Managing Your Graphics

The following examples illustrate the basics of using ODS Graphics.

Selecting Graphs

Procedures assign a name to each graph they create with ODS Graphics. This enables you to refer to ODS graphs in the same way that you refer to ODS tables. To determine which output objects are created by ODS, you can specify the ODS TRACE ON statement prior to the procedure statements.

   ods trace on;

You can then use the ODS SELECT statement to restrict your output to a particular subset of ODS tables or graphs.

   ods html;
   ods graphics on;

   ods select CooksD;

   proc reg data = sashelp.class plots(unpack); 
      model Weight = Height; 
   run;
   quit;

   ods graphics off;
   ods html close;
This results in a graph of Cook's D only.

Excluding Graphs

You can use the ODS EXCLUDE statement to display all the output with the exception of a particular subset of tables or graphs. For example, to exclude the diagnostics panel and the Number of Observations table from the output you specify

   ods html;
   ods graphics on;

   ods exclude NObs DiagnosticsPanel;

   proc reg data = sashelp.class; 
      model Weight = Height; 
   run;
   quit;

   ods graphics off;
   ods html close;
The results are appropriately modified.

Specifying a File for ODS Output

You can specify a file name for your output with the FILE option in the ODS destination statement, as in the following example:

   ods html file = "test.htm";
   ods graphics on;

   proc reg data = sashelp.class; 
      model Weight = Height; 
   run;
   quit;

   ods graphics off;
   ods html close;

Specifying a Style

You can specify a style using the STYLE option in a valid ODS destination.

   ods html style = Styles.Journal;
   ods graphics on;

   proc reg data = sashelp.class; 
      model Weight = Height; 
   run;
   quit;

   ods graphics off;
   ods html close;
See the output file created with the Journal style, and compare this with the default style.

Naming Graphics Image Files

You can specify a base file name for all of your graphics image files with the IMAGENAME option in the ODS GRAPHICS statement. You can also specify the RESET option in the ODS GRAPHICS statement to reset the index counter to zero. This is useful to avoid duplication of graphics image files if you are rerunning a SAS program in the same session. For example:
   ods html;
   ods graphics on / imagename="MyName" reset;

   proc reg data = sashelp.class; 
      model Weight = Height; 
   run;
   quit;

   ods graphics off;
   ods html close;

Creating Graphs with Tool Tips in HTML

You can request tool tips for graphics with the HTML destination. The tips appear when you move a mouse over certain regions of the graph. When you specify the HTML destination and the IMAGEFMT=STATICMAP option in the ODS GRAPHICS statement, then the HTML file output file is generated with an image map of coordinates for tool tips. This feature is supported in Microsoft Internet Explorer 5.5 and higher.

   ods html;
   ods graphics on / imagefmt = staticmap;
   
   proc mixed data=pr method=ml boxplot(npanel=15);
      class Person Gender;
      model y = Gender Age Gender*Age;
      random intercept Age / type=un subject=Person;
   run;

   ods graphics off;
   ods html close;
Take a look at the resulting graph and make sure you move your mouse over some of the boxes of the box plot! The complete SAS program is available if you want to submit it yourself.

Creating Graphs in PostScript Files

The "Journal" style creates gray-scale graphs that are suitable for a journal article. When you specify the ODS LATEX destination, ODS creates a PostScript file for each individual graph in addition to a LaTeX source file that includes the tabular output and references to the PostScript files.

   ods latex style=Styles.Journal;
   ods graphics on;

   proc reg data = sashelp.class; 
      model Weight = Height; 
   run;
   quit;

   ods graphics off;
   ods latex close;

Specifying Multiple Destinations for ODS Output

You can specify multiple destinations as follows:
   ods html file = "test.htm";
   ods rtf  file = "test.rtf";
   ods pdf  file = "test.pdf";
   ods graphics on;

   proc reg data = sashelp.class; 
      model Weight = Height; 
   run;
   quit;

   ods graphics off;
   ods _all_ close;
   ods listing;
The ODS _ALL_ CLOSE statement closes all open destinations.

Statistics and Operations Research | Quality Improvement