• Print  |
  • Feedback  |

Knowledge Base


TS-426

HOW CAN I AUTOMATICALLY UPDATAE A PERMANENT CATALOG WITH A NEW GRAPH WHEN I CREATE THE GRAPH?

INPUT:

I am developing a series of graphs to illustrate my company's annual report. I want to be able to review the graphs at any time, so I store them in a permanent catalog. The catalog, REPRTCAT, is in a library I refer to with the libref LIB94. The problem I have is that every time I revise one of the graphs, I have to go through several steps to move the new version from the temporary catalog WORK.GSEG to my permanent catalog, LIB94.REPRTCAT.

For example, I used the GSLIDE procedure to create the title slides and stored them in the permanent catalog as TITLE1, TITLE2, and so forth. When I revise a slide by rerunning the GSLIDE program, SAS/GRAPH automatically stores the new version in WORK.GSEG as GSLIDE, or GSLIDE and some number like GSLIDE3 if I have run the program more than once. When I have the slide the way I want it, I have to rename the temporary catalog entry in WORK.GSEG and then copy the entry to the permanent catalog LIB94.REPRTCAT. This is how I do it:

  1. Using the CATALOG window, I rename the new graph in the WORK.GSEG catalog (for example, WORK.GSEG.GSLIDE5 becomes WORK.GSEG.TITLE2).
  2. Again using the CATALOG window, I delete the old version of the graph from my permanent catalog (LIB94.REPRTCAT.TITLE2).
  3. Finally, I use the GREPLAY procedure to copy the new version (WORK.GSEG.TITLE2) into my permanent catalog as LIB94.REPRTCAT.TITLE2.

How can I eliminate some of these steps and automatically update the permanent catalog with the new graph when I create it?

OUTPUT:

You can simplify this process by working directly in the permanent catalog and bypassing the temporary catalog, WORK.GSEG. This method requires only two short steps that can be added to each program that generates a graph:

    At the beginning of your program, use the GREPLAY procedure in line mode to remove it from the permanent catalog the entry you'll be replacing. For example, this is how you delete the graph called TITLE2 from LIB94.REPRTCAT.

         /* Invoke GREPLAY in line mode (NOFS option).           */
         /* Specify the permanent catalog (IGOUT= option).       */
      proc greplay nofs igout=lib94.reprtcat;
    
         /* Delete the existing entry, TITLE2.                   */
          delete title2;
      run;
      quit;
    

  1. When you create the new graph, store it directly in the permanent catalog. In the PROC statement, use the GOUT= option to specify the permanent catalog. Use the NAME= option in the PROC statement or the action statement to assign the name of the permanent entry to the graphics output. For example, these statments create TITLE2 and store it in the permanent catalog.

         /* Specify the text of the slide.                       */
      title1 font=swissb height=6 'Section 2: 1990 to Present';
    
         /* Produce the slide and specify the permanent          */
         /* catalog with the GOUT= option.                       */
         /* Assign the entry name, TITLE2, with the              */
         /* NAME= option.                                        */
      proc gslide border gout=lib94.reprtcat name='title2';
      run;
      quit;
    

    Every time you run the program that includes these two steps, the entry in the permanent catalog is automatically replaced.

In the GSLIDE procedure, the NAME= option is part of the PROC statement. In other prcedures, it is part of the action statement. IF your program produces multiiple graphs, you may want to create each one with a separate action statement so you can explicitly assign a name to each graph.

For example, to automate replacement of two plots called COSTSQ1 and COSTSQ2, your program might look like this:

     /* Delete existing entries from the permanent catalog   */
  proc greplay nofs igout=lib94.reprtcat;
     delete costsq1 costsq2;
  run;
  quit;


     /* Create the plots and specify the permanent catalog.  */
  proc gplot data=datalib.curexp gout=lib94.reprtcat;

     /* Define the title for the first plot.                 */
  title1 font=swiss height=4 'Total Expenses: First Quarter';

     /* Create and name the first plot.                      */
  plot exp*q1 / name='costsq1';
  run;

     /* Define the title for the second plot.                */
  title1 font=swiss height=4 'Total Expenses: Second Quarter';

     /* Create and name the second plot.                     */
  plot exp*q2 / name='costsq2';
  run;
  quit;

Note: If you are working with templated graphs, you must delete the template entry as well as the graphs that are included in the template.