Statistical Graphics Using ODS

Selecting and Excluding Graphs

You can use the ODS SELECT and ODS EXCLUDE statements along with graph and table names to specify which ODS outputs to display. For more information about how to use these statements, see the section The ODS Statement in ChapterĀ 20: Using the Output Delivery System.

This section shows several examples of selecting and excluding graphs by using the data set and trace output that are created in the section Determining Graph Names and Labels. The following statements use the ODS SELECT statement to select only two graphs, ContourPlot and SurfacePlot, for display in the output:

proc kde data=bivnormal;
   ods select ContourPlot SurfacePlot;
   bivar x y / plots=contour surface;

Equivalently, the following statements use the ODS EXCLUDE statement to exclude the two tables:

proc kde data=bivnormal;
   ods exclude Inputs Controls;
   bivar x y / plots=contour surface;

You can select or exclude graphs by using either the name or the label. Labels must be specified in quotes. In the context of this example, the following two statements are equivalent:

ods select contourplot;
ods select 'Contour Plot';

You can also specify multiple levels of the path, as in the following examples:

ods select x_y.contourplot;
ods select 'x and y'.'Contour Plot';
ods select 'x and y'.contourplot;
ods select x_y.'Contour Plot';

You can mix name and label paths, as in the last two statements. All four of the preceding statements select the same plot. Furthermore, selection based directly on the names and labels is case-insensitive. The following statements all select the same plot:

ods select x_y.contourplot;
ods select 'x and y'.'Contour Plot';
ods select X_Y.CONTOURPLOT;
ods select 'X AND Y'.'CONTOUR PLOT';

It is sometimes useful to specify a WHERE clause in an ODS SELECT or ODS EXCLUDE statement. This enables you to specify expressions based on either the name path or the label path. You can base your selection on two automatic variables, _path_ and _label_. The following two statements select every object whose path contains the string 'plot' and every object whose label path contains the string 'plot', respectively, ignoring the case in the name and label:

ods select where = (lowcase(_path_)  ? 'plot');
ods select where = (lowcase(_label_) ? 'plot');

The question mark operator means that the second expression (the string 'plot') is contained in the first expression (the lowercase version of the name or label). For example, all the following names match 'plot' in the WHERE clause: plot, SurfacePlot, SURFACEPLOT, FitPlot, pLoTtInG, Splotch, and so on. Because WHERE clause selection is based on SAS string comparisons, selection is case-sensitive. The LOWCASE function is used to ensure a match even when the case of the specified string does not match the case of the actual name or label.

WHERE clauses are particularly useful when you want to select all the objects in a group. A group is a level of the name path or label path hierarchy before the last level. In the following step, all the objects whose name path contains 'DiagnosticPlots' are selected:

proc reg data=sashelp.class plots(unpack);
   ods select where = (_path_ ? 'DiagnosticPlots');
   model Weight = Height;
run; quit;

These are the plots that come from unpacking the PROC REG diagnostics panel of plots. All are in a group named 'DiagnosticPlots'.