GREPLAY Procedure

Example 4: Replaying a Graph to Multiple Destinations

Features:
GREPLAY statement options::
IGOUT=
NOFS
TC=

DELETE statement

TDEF statement

TDELETE statement

TREPLAY statement

Other features:

FILENAME statement

ODS HTML statement

ODS PDF statement

ODS RTF statement

GOPTIONS statement::
BORDER
DEVICE=
GSFNAME=
NOBORDER
NODISPLAY
XPIXELS=
YPIXELS=

OPTIONS statement ORIENTATION= option

PROC GCHART

The GREPLAY procedure replays the graph shown in Vertical Bar Chart Exported to Multiple Destinations to a TIF file, and the ODS HTML, PDF, and RTF destinations. A template is used to generate the initial graph. The template creates a margin and a blue border around the graph. The XPIXELS= and YPIXELS= graphics options are used to set the graph size. The GREPLAY procedure TREPLAY statement is used to replay the graph to each of the destinations. For the ODS PDF and RTF destinations, the system option ORIENTATION= is set to LANDSCAPE to orient the graph in landscape in both documents.
Vertical Bar Chart Exported to Multiple Destinations
Vertical Bar Chart Exported to Multiple Destinations

Program

%let goutname=height;
proc greplay nofs tc=work.tempcat igout=work.gseg;
   delete &goutname;
   tdelete grtemp;
run;
quit;
proc greplay tc=work.tempcat nofs;
   tdef grtemp des="One panel template with border"
      1/llx=5   lly=5
        ulx=5   uly=95
        urx=95  ury=95
        lrx=95  lry=5
      color=cx7C95CA;
run;
quit;
goptions reset=all nodisplay noborder xpixels=520 ypixels=520;
ods html close;
ods listing style=listing;
title "Average Height by Age and Sex";
proc gchart data=sashelp.class;
   vbar age / sumvar=height discrete type=mean group=sex name="&goutname";
run;
quit;
filename tifout ".\&goutname..tif";
goptions display device=tiffp gsfname=tifout;
proc greplay nofs tc=work.tempcat igout=work.gseg;
   template grtemp;
   treplay 1:&goutname name="t&goutname";
run;
quit;
goptions reset=all device=png noborder xpixels=520 ypixels=520;
options orientation=landscape;
ods listing close;
ods html file="&goutname..html" style=listing;
ods pdf file="&goutname..pdf" style=listing;
ods rtf file="&goutname..rtf" style=listing image_dpi=72;
proc greplay nofs tc=work.tempcat igout=work.gseg;
   template grtemp;
   treplay 1:&goutname name="t&goutname";
run;
quit;
options orientation=portrait;
ods _all_ close;
ods html;

Program Description

Here is a detailed example of the example program.
Define a name variable to use for specifying the graph output name. Using a macro variable makes it easier to change the name, if necessary.
%let goutname=height;
Delete the old GRSEG and template, if they exist. The DELETE statement deletes entry HEIGHT from the WORK catalog, which is specified by the IGOUT= option. The TDELETE statement deletes template GRTEMP in the WORK.TEMPCAT catalog, which is specified by the TC= option.
proc greplay nofs tc=work.tempcat igout=work.gseg;
   delete &goutname;
   tdelete grtemp;
run;
quit;
Create a one-panel template for the graph. This template specifies a 5% margin around the graph. The COLOR= option specifies a blue border around the graph.
proc greplay tc=work.tempcat nofs;
   tdef grtemp des="One panel template with border"
      1/llx=5   lly=5
        ulx=5   uly=95
        urx=95  ury=95
        lrx=95  lry=5
      color=cx7C95CA;
run;
quit;
Set the graphics options. The GOPTIONS statement NODISPLAY option prevents the chart from being displayed when it is generated. The NOBORDER option disables the graph border, since template GRTEMP draws its own border. Options XPIXELS= and YPIXELS= set the graph dimensions to 520–by-520 pixels.
goptions reset=all nodisplay noborder xpixels=520 ypixels=520;
Close the ODS HTML destination.
ods html close;
Open the LISTING destination. Use the LISTING style.
ods listing style=listing;
Generate the chart. The NAME= option in the VBAR statement sets the name of the GRSEG entry to HEIGHT.
title "Average Height by Age and Sex";
proc gchart data=sashelp.class;
   vbar age / sumvar=height discrete type=mean group=sex name="&goutname";
run;
quit;
Create a fileref for the graphics output file.
filename tifout ".\&goutname..tif";
Replay GRSEG entry HEIGHT to TIFF file height.tif. The GOPTIONS statement DEVICE= option sets the output device to TIFFP, and the GSFNAME= option specifies the output filename as height.tif. The TREPLAY statement replays GRSEG entry HEIGHT to entry THEIGHT using the panel 1 template in template GRTEMP.
goptions display device=tiffp gsfname=tifout;
proc greplay nofs tc=work.tempcat igout=work.gseg;
   template grtemp;
   treplay 1:&goutname name="t&goutname";
run;
quit;
Change device to PNG and disable borders. Because a border is included in the original GRSEG, the GOPTIONS statement NOBORDER option is used to prevent ODS from drawing another border around the image.
goptions reset=all device=png noborder xpixels=520 ypixels=520;
Replay GRSEG entry HEIGHT to the HTML, PDF, and RTF destinations. The OPTIONS statement ORIENTATION=LANDSCAPE option sets the graph orientation to landscape in the PDF and RTF documents. This option does not affect the ODS HTML destination. The LISTING style is used with each destination.
options orientation=landscape;
ods listing close;
ods html file="&goutname..html" style=listing;
ods pdf file="&goutname..pdf" style=listing;
ods rtf file="&goutname..rtf" style=listing image_dpi=72;
proc greplay nofs tc=work.tempcat igout=work.gseg;
   template grtemp;
   treplay 1:&goutname name="t&goutname";
run;
quit;
Reset the ORIENTATION= system option to PORTRAIT.
options orientation=portrait;
Close all of the open destinations, and then open the HTML destination.
ods _all_ close;
ods html;