Sample 24940: Dynamically replay all GSEG entries
/* The following program will do the following dynamically: */
/* - create a template with sufficient number of panels inorder to generate */
/* all the entries from a catalog on one page. (3 panels across) */
/* - generate the TREPLAY statement inorder to replay the entries into */
/* the template panels */
/* - adjust for correct aspect ratio during creation of individual graphs */
/* Resolved values of used macro variables will appear in SASLOG */
options mprint macrogen symbolgen;
/* Specify TARGETDEVICE */
goptions target=ps;
/* Clear out GSEG catalog */
proc greplay nofs igout=work.gseg;
delete _all_;
run;
/* 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/3;
call symput('hsize',left(trim(hsze)));
call gask('vsize',vsize,rc);
vsze=vsize/(&panels/3);
call symput('vsize',left(trim(vsze)));
rc=gterm();
run;
data one;
input xvar yvar type $;
datalines;
2 4 a
4 4 a
2 5 b
4 5 b
2 6 c
4 6 c
;
/* Modify VSIZE and HSIZE for correct aspect ratio, */
/* DISPLAY is turned off */
goptions nodisplay hsize=&hsize vsize=&vsize;
axis1 label=none;
proc gplot data=one;
plot yvar*xvar/vaxis=axis1;
by type;
symbol1 v=star i=join h=2 c=black;
run;
quit;
proc gchart data=one;
vbar xvar /discrete sumvar=yvar patternid=midpoint raxis=axis1;
by type;
pattern1 v=solid c=black;
pattern2 v=X3 c=black;
run;
quit;
/* Use DSGI function NUMGRAPH to determine the number of entries in */
/* GSEG CATALOG. */
data numgraf;
rc=gset('catalog','work','gseg');
rc=ginit();
call gask('numgraph',grsegcnt,rc);
call symput('grsegcnt',left(trim(grsegcnt)));
if mod(grsegcnt,3) ^=0 then
panels=grsegcnt+ (3 - mod(grsegcnt,3));
if mod(grsegcnt,3) =0 then
panels=grsegcnt;
call symput('panels',left(trim(panels)));
ymult=100/(panels/3);
xmult=100/3;
rc=gterm();
run;
/* Calculate the panel coordinates */
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 replay entries into template */
%macro tplay;
%do i=1 %to &grsegcnt;
&i:&i
%end;
%mend tplay;
/* Reset HSIZE and VSIZE, */
/* turn DISPLAY on */
goptions display hsize=0 vsize=0;
proc greplay nofs igout=work.gseg tc=work.templt;
tdef spec&panels
/* Invoke macro TEMPDEF */
%tempdef;
template spec&panels;
treplay
/* Invoke macro TPLAY */
%tplay;
run;
quit;

This sample program dynamically replays all GRSEG entries from a catalog into a template defined with 3 panels across and a calculated number of panels down.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GREPLAY
|
| Date Modified: | 2005-08-31 03:03:24 |
| Date Created: | 2004-11-11 11:08:04 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |