/*stp.sas.com/tech/download/sample/graph/greplay_perpage.html*/ /*see also: http://www.math.yorku.ca/SCS/friendly.html*/ /* 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; goptions reset=all noborder ftext=titalic nocell rotate = portrait htext=4 hby=0 vsize=7.9 hsize=7; symbol color=black i=none value=dot height=2 ; axis1 label=('OCCASION' ) minor=none ; axis2 label = none order=(0 to 4 by 1) minor=none; proc gplot data=rus.ruswork1 gout=graph1 uniform ; note justify=center 'ID #byval(ID)'; symbol color=black interpol=spline value=dot height=2 ; by id; plot motiv*occasion / nolegend haxis=axis1 vaxis=axis2 noframe; run; /*libname rus 'C:\1datalap\papers\walls_sork'; proc gplot uniform data = rus.ruswork1; where grade = 6; plot metacog * occasion / nolegend noframe; by id; run;*/ %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=3,down=4);