Sample 24944: Replay specified number of graphs per page
/* The purpose of this program is to dynamically create and use a template */
/* to replay a specified number of grseg entries per page. */
options mprint macrogen symbolgen;
/* Specify TARGETDEVICE */
goptions reset=all target=ps;
/* Macro MAKEGRAF creates GSLIDE graph entries that are TREPLAYED */
/* by PROC GREPLAY later in this program. Remove the %DO loop and GSLIDE */
/* procedure and place your code within the MAKEGRAF macro when you are */
/* ready to create your own individual graph entries. */
%macro makegraf;
%do i=1 %to 10;
proc gslide;
title1 "test&i";
run;
quit;
%end;
%mend makegraf;
/* Macro will dynamically treplay a specified number of grseg entries */
/* per page/screen. The specified values for the parameters */
/* ACROSS and DOWN will determine the number of panels in the template */
/* and the number of graphs per page/screen. */
%MACRO PERPAGE(across,down);
/* Delete entries from WORK.GSEG catalog */
proc greplay nofs igout=work.gseg;
delete _all_;
run;
/* Create macro variable perpage */
%let perpage=%eval(&across*&down);
/* Use DSGI functions HSIZE/VSIZE to determine default HSIZE and VSIZE */
/* and modify for correct aspect ratio. */
data garea;
rc=ginit();
call gask('hsize',hsize,rc);
hsze=hsize/&across;
call symput('hsize',left(trim(hsze)));
call gask('vsize',vsize,rc);
vsze=vsize/&down;
call symput('vsize',left(trim(vsze)));
rc=gterm();
run;
/* Adjust VSIZE and HSIZE to reflect dimension of template panel. */
/* Turn DISPLAY off. */
goptions nodisplay vsize=&vsize hsize=&hsize;
/* Invoke macro MAKEGRAF, */
/* gslide entries created in WORK.GSEG catalog. */
%makegraf
/* Use dsgi function NUMGRAPH to determine the number of entries in */
/* WORK.GSEG catalog. */
data numgraf;
rc=gset('catalog','work','gseg');
rc=ginit();
call gask('numgraph',grsegcnt,rc);
call symput('grsegcnt',grsegcnt);
call symput('loopit',ceil(grsegcnt/&perpage));
ymult=100/&down;
xmult=100/&across;
rc=gterm();
run;
/* Calculate the panel coordinates for template */
data coord;
set numgraf;
do x=0 to (100-xmult) by xmult;
llx=x;
ulx=x;
urx=x+xmult;
lrx=x+xmult;
do y=0 to (100-ymult) by ymult;
lly=y;
uly=y+ymult;
ury=y+ymult;
lry=y;
output;
end;
end;
run;
proc sort;
by descending y;
run;
/* Create macro variables that resolve to panel coordinates */
data mccoord;
set coord end=eof;
call symput('llx'||left(_n_),llx);
call symput('ulx'||left(_n_),ulx);
call symput('urx'||left(_n_),urx);
call symput('lrx'||left(_n_),lrx);
call symput('lly'||left(_n_),lly);
call symput('uly'||left(_n_),uly);
call symput('ury'||left(_n_),ury);
call symput('lry'||left(_n_),lry);
if eof then call symput('total',_n_);
run;
/* Macro to create template */
%macro tempdef;
%do i=1 %to &total;
&i / llx=&&llx&i lly=&&lly&i
ulx=&&ulx&i uly=&&uly&i
urx=&&urx&i ury=&&ury&i
lrx=&&lrx&i lry=&&lry&i
color=black
%end;
%mend tempdef;
/* Macro to generate TREPLAY statement for GREPLAY */
%macro tplay;
%do j=1 %to &perpage;
%if %eval(&i*&perpage-(&perpage-&j)) <= &grsegcnt %then
&j:%eval(&i*&perpage-(&perpage-&j));
%end;
%mend tplay;
/* Macro to generate templated grseg entries */
%macro greplay;
proc greplay nofs igout=work.gseg tc=tempcat;
tdef spec&perpage
%tempdef;
template spec&perpage;
%do i=1 %to &loopit;
treplay %tplay;
run;
%end;
quit;
%mend greplay;
/* Turn DISPLAY on. */
/* Reset VSIZE and HSIZE to their default values. */
goptions display vsize=0 hsize=0;
/* Invoke GREPLAY macro */
%greplay
%MEND PERPAGE;
/* Specify the number of panels across and down for template */
%PERPAGE(across=2,down=3);

The purpose of this program is to dynamically create and use a template to replay a specified number of grseg entries per page.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GREPLAY
|
| Date Modified: | 2005-09-01 03:03:07 |
| Date Created: | 2004-11-11 11:08:05 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |