Sample 24942: Dynamically replay GCHART and GPLOT on the same page
goptions reset=all colors=(black) border;
options mprint macrogen symbolgen;
/* This PROC GREPLAY makes sure the GSEG catalog is empty, */
/* OPTIONAL STEP. */
proc greplay nofs igout=work.gseg;
delete _all_;
run;
quit;
data one;
input x y type $;
datalines;
1 2 A
2 5 A
3 7 A
4 6 A
1 3 B
2 6 B
3 6 B
4 2 B
;
proc sort data=one;
by type;
run;
/* Dataset two: */
/* creating macro variable to return the BY group value in title, creating macro */
/* variable to return the first observation number in a BY group, */
/* creating a macro variable to return the last observation number */
/* in a BY group, checking end of file and then creating macro */
/* variables to return the number of iterations for the macro */
/* DO loops. */
data two;
set one end=eof; by type;
if first.type then do;
incr+1;
call symput('z'||left(incr),type);
call symput('first'||left(incr),left(_n_));
end;
if last.type then do;
call symput('last'||left(incr),left(_n_));
end;
if eof then do;
iter=incr-1;
call symput('total',incr);
call symput('loop',iter);
end;
run;
/* This macro generates 3 gplots based on the BY group of TYPE */
/* and saves them to the GSEG catalog. */
%macro gplot;
%do i=1 %to &total;
proc gplot data=two(firstobs=&&first&i obs=&&last&i) gout=work.gseg;
plot y*x/ haxis=axis1 vaxis=axis2;
axis1 order=(0 to 5 by 1) minor=none;
axis2 minor=none;
symbol1 v=dot c=blue i=join;
title1 "GROUP &&z&i";
run;
quit;
%end;
%mend gplot;
/* This macro generates 3 gcharts based on the BY group of TYPE */
/* and saves them to the GSEG catalog. */
%macro gchart;
%do i=1 %to &total;
proc gchart data=two(firstobs=&&first&i obs=&&last&i) gout=work.gseg;
vbar x/ discrete sumvar=y raxis=axis1;;
axis1 minor=none;
pattern1 v=solid c=blue;
title1 "GROUP &&z&i";
run;
quit;
%end;
%mend gchart;
goptions nodisplay vsize=4.25;
/* Executing gplot macro */
%gplot
/* Executing gchart macro*/
%gchart
/* This macro iterates through PROC GREPLAY based on the value of (&loop+1) */
%macro greplay;
proc greplay igout=work.gseg tc=sashelp.templt template=v2 nofs;
treplay 1:gplot
2:gchart;
run;
%do i=1 %to &loop;
proc greplay igout=work.gseg tc=sashelp.templt template=v2 nofs;
treplay 1:gplot&i
2:gchart&i;
run;
%end;
%mend greplay;
/* Executing greplay macro */
goptions display vsize=0;
%greplay
quit;

This sample program dynamically replays GCHART and GPLOT on the same page. The output is based on the BY values.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GREPLAY
|
| Date Modified: | 2005-09-01 03:03:07 |
| Date Created: | 2004-11-11 11:08:04 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |