Naming Graphics Image Files

The following discussion applies to the destinations where ODS graphs are created as individual image files (for example, HTML, LISTING, and LATEX). The names of graphics image files are determined by a base filename, an index counter, and an extension. By default, the base filename is the ODS graph name (see the section Determining Graph Names and Labels). There is an index counter for each base filename. The extension indicates the image file type. The first time a graph object with a given base filename is created, the filename consists only of the base filename and the extension. If a graph with the same base filename is created multiple times, then an index counter is appended to the base filename to avoid overwriting previously created images.

To illustrate, consider the following statements:

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

If you run this step at the beginning of a SAS session, the two graphics image files created are ContourPlot.png and SurfacePlot.png. If you immediately rerun these statements, then ODS creates the same graphs in different image files named ContourPlot1.png and SurfacePlot1.png. The next time, the image files are named ContourPlot2.png and SurfacePlot2.png. The index starts at zero, and one is added each time the same name is used. Note, however, that when the index is at zero, 0 is not added to the filename.

Resetting the Index Counter

You can specify the RESET=INDEX option in the ODS GRAPHICS statement to reset the index counter. This is useful when you need to have predictable names. It is particularly useful when you are running a SAS program multiple times in the same session. The following statement resets the index:

ods graphics on / reset=index;

The index counter is reinitialized at the beginning of your SAS session or if you specify the RESET=INDEX option in the ODS GRAPHICS statement. Graphics image files with the same name are overwritten.

Specifying Base Filenames

You can specify a base filename for all your graphics image files with the IMAGENAME= option in the ODS GRAPHICS statement as follows:

ods graphics on / imagename="MyName";

You can also specify the RESET=INDEX option as follows:

ods graphics on / reset=index imagename="MyName";

The IMAGENAME= option overrides the default base filename. With the preceding statement, the graphics image files are named MyName, MyName1, MyName2, and so on.

Specifying Image File Types

You can specify the image file type for the LISTING, HTML, or LATEX destinations with the OUTPUTFMT= option in the ODS GRAPHICS statement as follows:

ods graphics on / outputfmts=gif;

For more information, see the section ODS GRAPHICS Statement.

Naming Graphics Image Files with Multiple Destinations

Since the index counter depends only on the base filename, if you specify multiple ODS destinations for your output, then the index counter is increased independently of the destination. For example, the following statements create image files named ContourPlot.png and SurfacePlot.png that correspond to the LISTING destination, and ContourPlot1.png and SurfacePlot1.png that correspond to the HTML destination:

ods listing;
ods html;
ods graphics on / reset;

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

ods _all_ close;
ods listing;

When you specify one of the destinations in the PRINTER family or the RTF destination, your ODS graphs are embedded in the document, so the index counter is not affected. For example, the following statements create image files ContourPlot.png and SurfacePlot.png for the LISTING destinations, but no image files for the RTF destination:

ods listing;
ods rtf;
ods graphics on / reset;

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

ods _all_ close;