Introduction to SAS/Graph

Michael Friendly
Graphic Catalogs and GREPLAY


How to create and use a SAS Graphic Catalog(1)

SAS/Graph procedures produce graphics output. For display terminals, SAS/Graph sends commands directly to the device to draw lines, characters, etc. In addition, each plot that SAS/Graph creates is stored in a file called a "Graphic catalog" or a "GOUT= data set".

By default, the graphics catalog is a temprorary data set, and is erased when your SAS/Graph job completed. However, by specifying certain SAS options you can save the graphics catalog as a permanent file. You can then use Proc GREPLAY later to:

GREPLAY also provides a full-screen environment that helps you manage a graphics catalog. If you are producing a series of graphs for a paper or presentation, you can maintain them in the graphics catalog and plot them again as needed, without running the SAS program that created them originally.

Creating a Graphics Catalog

Each plot produced by a SAS/Graph procedure is stored in a graphic catalog. You can specify a one- or two-part name for the graphic catalog. If you want to store the output permanently, use a two-part name, as you would do to create or access any SAS permanent file simply by using a two-part name. For example, if you use GOUT=GRAPHS.PLOTLIB in a Proc GPLOT statement,
Proc GPLOT data=EXPER2;
     Plot RT * TRIAL / GOUT=GRAPHS.PLOTLIB
                       (other options)  ;
SAS will store the plot in the file 5PLOTLIB GRAPHS on your A-disk. If that file did not exist previously, it will be created.(2) If you wish to store or access a graphics catalog on a disk other than your A-disk, use the FILEDEF statement to define the file. For example, to store plots in a file on a B-disk (assuming you have Read/Write access to it) use:
CMS FILEDEF GRAPHS DISK dummy dummy B;
It is useful to place this line at the beginning of your SAS program to indicate clearly where the plots will be stored.
------------------------
(1) Portions of this document were taken from a paper, SASLIB DOC, by Richard Fournier.
------------------------
(2) SAS prepends the character "5" to the filename to indicate it was created with Version 5.nn of SAS. Thus under CMS the filename you use can be no more than 7 characters.
------------------------

If you specify a one-part name in a GOUT= option, the catalog will be stored in a WORK library. Thus the plot statement,

    Plot RT * TRIAL / GOUT=PLOTLIB;
creates a catalog WORK.PLOTLIB, which corresponds to the external file 5PLOTLIB WORK A, but WORK files are erased when your job completes. If you do not specify the GOUT= option, graphic catalog entries are written to a default catalog, WORK.GSEG.

VAX

On the VAX, the LIBNAME statement is used (instead of the CMS FILEDEF statement) to create a permanent SAS library. The statement should look like this:
     LIBNAME gcat_name 'disk_used';
e.g.,
     LIBNAME PLOTLIB 'A';

Sending plots to a Graphic Catalog

The way to place the generated plot in a particular library is to use the GOUT= option in any graphic procedure (e.g. GPLOT, G3D, GSLIDE,...). This option can appear either on the procedure statement, or on a plot request statement. The general format is:
      PROC graphproc  DATA=dataset  GOUT=graphicscatalog ;
e.g.,
      PROC GPLOT      DATA=EXPER2   GOUT=GRAPHS.PLOTLIB ;
or
           Plot RT*TRIAL / GOUT=GRAPHS.PLOTLIB;
In a program you can direct different plots to different graphic catalogs if you wish to segregate them in some way.

By default, any plots produced are added to the end of the catalog. If a procedure produces several graphs, an entry is made in the catalog for each one.(3)

If you wish to store a series of plots in a catalog, but don't want to have them displayed or plotted now, use the NODISPLAY option on the GOPTIONS statement:

GOPTIONS NODISPLAY;

Generalizing the GOUT= option

If you are generating a series of plots with different programs, it may be a nuisance to change the GOUT= option to direct plots to a different catalog. One way to generalize the destination is to use a SAS macro variable, &GOUT in every SAS/Graph procedure. For example,
PROC G3D data=NORMAL2;
     PLOT Y * X = Z /
              &GOUT
              NAME='NORMAL2'
              DES ='Bivariate normal 3D plot';
The include file, GRAPHICS SAS, contains a statement assigning GOUT a null value (if it is not already defined)
%GLOBAL GOUT;
If you do not redefine GOUT, it will have no effect (the plots will not be stored permanently). However, if you include a statement such as
%LET GOUT= GOUT=GRAPHS.PLOTLIB;

------------------------
(3) If you specify GOPTIONS GOUTMODE=REPLACE;, the new graphs replace any existing plots in the catalog.
------------------------
before any SAS/Graph procedure, all your plots will be stored there.

Documenting the stored plots

When your output is sent to a graphics catalog, SAS/Graph automatically assigns a name and description to each plot so you can identify it. By default, the name of the plot is same as the name of the SAS/Graph procedure, and the description usually includes the type of plot and name of the variable(s) plotted. For example, suppose you run Proc GCHART and then Proc GMAP, and each procedure produces one graph. If you do not supply a name or description, SAS/Graph might store these entries:
GCHART     PIE CHART OF REGION
GMAP       CHOROPLETH MAP OF SPACES
You can also supply your own name and description as options to some of the SAS/Graph procedures (G3D, GMAP, GANNO, GCHART and GCONTOUR). For example, you might have used these statements to create the map:
Proc GMAP MAP=MAPS.CANADA
          DATA=DAYCARE
          GOUT=GRAPHS.PLOTLIB;
     ID PROVINCE;
     CHORO SPACES /
          NAME = 'SPACEMAP'
          DES  = 'Number of Licensed day care spaces' ;
It is strongly recommended that you use these options, to save confusion later over which plot is which. If you don't supply a name or description when the plot is created, you can always change them later with GREPLAY.
PROC G3D data=NORMAL2;
     PLOT Y * X = Z /
              GOUT=GRAPHS.PLOTLIB
              NAME='NORMAL2'
              DES ='Bivariate normal 3D plot'
             ... (other options) ...   ;
    RUN;

How to retreive plots from the library

The procedure GREPLAY was designed for this purpose. Proc GREPLAY can be used in two ways: The FS (full-screen) and NOFS (line mode) options on the Proc GREPLAY statement determine which mode is used. On CMS, FS is the default, so if you run a SAS program in batch without specifying either FS or NOFS, you will enter full-screen mode.

For some applications, such as those described in Introduction to SAS/Graph: Tutorial Examples, (Friendly, 1988), line mode is used to create and display a template containing multiple graphs. However, for managing a graphics catalog, the the full screen GREPLAY editor is more convenient.

Lets assume we have defined a library called "GRAPHS" with the FILEDEF statement. We also stored all the plots in the graphics catalog called "PLOTLIB" by specifying GOUT=GRAPHS.PLOTLIB in SAS/Graph procedures. The following sequence will allow you to get any plot stored in PLOTLIB. Assume you are using a TEK4010 compatible screen and you want SAS to list the plots on the screen. The example below shows how you would run SAS interactively to You type in the lines shown below after the ? prompt. This sequence is equivalent to writing a SAS program on-line. Use PF3 to submit these lines to SAS for execution.

R;
SAS                            * You invoke SAS ;
 
1? %GSTART(KEYNOTE);
2? CMS FILEDEF GRAPHS DISK dummy dummy A;
3? PROC GREPLAY IGOUT=GRAPHS.PLOTLIB FS;
4? LIST IGOUT;              * List all the plots stored in
                              this catalog;
With Proc GREPLAY, you can define both an input graphic catalog (using the IGOUT= option), and an output graphic catalog (using the GOUT= option), and these can refer to the same catalog file (if you want to modify the catalog), or to different catalogs (if you want to copy plots from one to another).

The LIST IGOUT statement displays a list of the graphs in the input catalog. The GREPLAY screen should appear with a listing of the plots stored in the catalog defined, as shown in Figure 1. +-------------------------------------------------------------------+ | | |

SAS/GRAPH GREPLAY
| | | | IGOUT: GRAPHS.PLOTLIB GOUT: _________________ Device: TEK4010 | TC: _________________ Template: ________ Scroll: PAGE | CC: _________________ Cmap: ________ | | | | Sel Name Type Description Created | | | | ___ NORMAL I Normal density GPLOT 04MAY88 | | ___ NORMAL2 I Bivariate normal 3D plot 04MAY88 | | ___ SPACEMAP I Number of Licensed day care 04MAY88 | | ___ EXP2RT I RT vs TRIAL for Experiment 2 04MAY88 | | | | | | | | | | ______________________________________________________________________ | PF1=HELP PF2=TC PF3=END PF4=CICS PF5=MODIFY | | PF5=NOFS PF7=UP PF8=DOWN PF9=GROUP PF10=PRES PF11=CC | | | | | | Figure 1: List of graphs in a | | graphics catalog | | | +-------------------------------------------------------------------+
The  Type field in the display indicates whether the graph was
created as a  device-independent (I) graph, or as a 
device-dependent graph. Only device-independent graphs can be
replayed through templates.
 

At this point you can do any of the following:

Replay graphs in the list.
To select plots to replay, type an S in the Sel (for SELECT) field beside the name of each graph you wish to replay
Change name or description information.
To change the name or description for any of your graphs, press the MODIFY function key (PF5). Modify these fields by typing the new information over the old. When you have finished making changes, press PF5 again, and your changes will be saved.
Create logical groupings of your graphs.
To make it easier to manage a collection of graphs, or to prepare a presentation, you can arrange the graphs in your catalog in groups that can be replayed later. To create groups, press the GROUP function key (PF9). You are given the prompt:
SELECT GROUPS, PRESS ENTER TO STOP
Define the groups by typing letters and digits in the Sel field beside each name. For example, use A1, A2, A3 to denote group "A", with three members ordered by the digits 1, 2, 3. After you press ENTER, the plots are reordered in the display screen according to the groups.
Delete graphs from your catalog.
Type the letters "DEL" in the Sel field next to any graph you want to delete.

Note: You are not prompted to confirm a request to delete a graph, so be careful.

Quit GREPLAY.
To get out of the GREPLAY screen press PF3. The word BYE in the command area of the SAS line editor (or pressing PF3 again) returns you to the operating system.