Storing Multiple Graphs in a Single Graphics Output File

If you want to store multiple graphs in a single graphics output file, you can use either the GSFMODE=APPEND and GSFNAME= graphics options, or the GREPLAY procedure.

Using Graphics Options to Store Multiple Graphs in One Graphics Output File

You can use the GSFMODE=APPEND and the GSFNAME= graphics options to store multiple graphs in one graphics output file. When the GSFMODE= graphics option is set to APPEND and the GSFNAME= option points to a file, if the graphics output file specified by the GSFNAME= option already exists, the SAS/GRAPH software appends the new graph to the graphics output file. Otherwise, it creates the graphics output file and stores the graph in it.
Note: Although a file can contain multiple graphs, some viewers can view only one graph. This can make it appear that a file containing multiple graphs contains only one graph.
The GSFMODE=APPEND option is useful only with the GIF graphics output device, and the PCL and PostScript Universal Printer devices. When used with other devices, such as PNG, SVG, or PDF, only the first graph is displayed in the viewer. A common application of the GSFMODE=APPEND option is in the production of animated GIFs. See Developing Web Presentations with the GIFANIM Device.

Using the GREPLAY Procedure to Store Multiple Graphs in One Graphics Output File

You can use the GOUT= procedure option with the GREPLAY procedure to store multiple graphs in one graphics output file. This involves the following steps:
  1. Create a file reference for your output file. For example:
    filename myfile "MyOutputFile.ps";
  2. Run the procedure to generate your charts and store them in a catalog.
  3. Add the GSFNAME=FileRefName to your GOPTIONS statement.
  4. Run the GREPLAY procedure as follows:
    proc greplay
       igout=<CatalogName>
          replay _all_;
       run;
    quit;
    Replace <CatalogName> with the name of the catalog in which your graphs are stored. The REPLAY _ALL_ action statement replays all of the entries in the catalog.
Here is an example that replays five graphs to one PostScript file for printing.
/* Specify graphics output file name */
filename psout "multicharts.ps";

/* Close the ODS HTML destination */
ods html close;

/* Specify the graphics options */
goptions reset=all device=pscolor gsfname=psout nodisplay;

/* Open the LISTING destination */
ods listing style=banker;

/* Generate the graphs */
proc gchart data=sashelp.cars gout=Work.Mygraphs;
   vbar Make;
      title1 "30 MPG or better";
      where MPG_Highway > 30;
   run;

      vbar Make;
      title1 "Between 25 MPG and 29 MPG";
      where MPG_Highway >= 25 AND MPG_Highway <= 29;
   run;

   vbar Make;
      title1 "Between 20 MPG and 24 MPG";
      where MPG_Highway >= 20 AND MPG_Highway <= 24;
   run;

   vbar Make;
      title1 "Between 15 MPG and 19 MPG";
      where MPG_Highway >= 15 AND MPG_Highway <= 19;
   run;

   vbar Make;
      title1 "Less than 15 MPG";
      where MPG_Highway < 15;
   run;
quit;

/* Enable display, and then replay all of the graphs to psout */
goptions display;
proc greplay
   igout=Work.Mygraphs nofs;
      replay _all_;
   run;
quit;

/* Close the LISTING destination and open the HTML destination */
ods listing close;
ods html;