Sample 24942: Use PROC GREPLAY to dynamically replay GCHART and GPLOT output on the same page
This sample uses PROC GREPLAY to dynamically replay GCHART and GPLOT output on the same page. The output is based on the values of the BY variable.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample uses PROC GREPLAY to dynamically replay GCHART and GPLOT output on the same page. The output is based on the values of the BY variable.
The graphics output in the Results tab was produced using SASĀ® 9.2. Submitting
the sample code with releases of SAS prior to SAS 9.2 might produce different results.
/* Set macro debugging options */
options mprint mlogic symbolgen;
/* Delete all of the old graphs from */
/* WORK.GSEG if necessary. */
proc greplay nofs igout=work.gseg;
delete _all_;
run;
quit;
/* Create a sample data set */
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
;
run;
proc sort data=one;
by type;
run;
/* Data set 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 offset=(5pct,5pct);
symbol1 font=marker v=U c=CX7C95CA i=none h=2;
title1 "GROUP &&z&i";
footnote1 angle=90 h=3 ' ';
footnote2 angle=-90 h=3 ' ';
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 width=18;
axis1 minor=none;
pattern1 v=solid c=CX7C95CA;
title1 "GROUP &&z&i";
run;
quit;
%end;
%mend gchart;
/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;
goptions device=gif nodisplay xpixels=600 ypixels=200;
/* Execute the GPLOT macro */
%gplot
/* Execute the 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;
quit;
%do i=1 %to &loop;
proc greplay igout=work.gseg tc=sashelp.templt template=v2 nofs;
treplay 1:gplot&i
2:gchart&i;
run;
quit;
%end;
%mend greplay;
/* Reset the graphics environment */
goptions reset=goptions device=gif
gsfname=grafout gsfmode=replace
xpixels=600 ypixels=400;
filename grafout 'c:\temp';
/* Execute the GREPLAY macro */
%greplay
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample uses PROC GREPLAY to dynamically replay GCHART and GPLOT output on the same page. The output is based on the values of the BY variable.
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 |