Sample 24913: Maintain symbols across by values
/**********************************************/
/* The BY statement is replaced with a WHERE */
/* statement and placed in a macro DO loop. */
/* Macro variables are used to create SYMBOL */
/* statements that will be maintained across */
/* by values. */
/**********************************************/
/* Set graphics environment */
goptions reset=all target=gif border;
/* Delete all entries in WORK.GSEG catalog */
proc greplay nofs igout=work.gseg;
delete _all_;
run;
/* Turn on options for debugging macros */
options symbolgen mlogic mprint;
/* Create input data set, ICECREAM */
data icecream;
input flavor rank z $ grp $;
datalines;
1 1 a x
2 1 a x
2 2 b x
3 2 b x
3 3 c x
4 3 c x
4 4 d x
4 5 d x
1 1 a y
2 1 a y
3 3 c y
4 3 c y
2 2 b z
3 2 b z
4 4 d z
4 5 d z
;
proc sort data=icecream;
by grp z;
run;
/* Create data set, NEW, which contains macro variables that resolve to form SYMBOL statements */
data new;
set icecream end=eof;
by grp z;
if first.grp then do;
bycount=0;
total+1;
end;
if first.z then do;
bycount+1;
call symput('grp'||left(total),grp);
if z='a' then do;
call symput('pat'||trim(left(total))||trim(left(bycount)),
'symbol'||trim(left(total))||trim(left(bycount))
|| ' '|| 'c=pink'|| ' '||'v=dot'||' '|| 'i=j'|| ' '||';');
end;
if z='b' then do;
call symput('pat'||trim(left(total))||trim(left(bycount)),
'symbol'||trim(left(total))||trim(left(bycount))
|| ' '|| 'c=brown'|| ' '||'v=dot'||' '|| 'i=j'|| ' '||';');
end;
if z='c' then do;
call symput('pat'||trim(left(total))||trim(left(bycount)),
'symbol'||trim(left(total))||trim(left(bycount))
|| ' '|| 'c=yellow'|| ' '||'v=dot'||' '|| 'i=j'|| ' '||';');
end;
if z='d' then do;
call symput('pat'||trim(left(total))||trim(left(bycount)),
'symbol'||trim(left(total))||trim(left(bycount))
|| ' '|| 'c=tan'|| ' '||'v=dot'||' '|| 'i=j'|| ' '||';');
end;
end;
if last.grp then call symput('totnby'||trim(left(total)),bycount);
if eof then call symput('total',total);
run;
/* Create macro that contains all symbol statements */
%macro symbol;
%do j=1 %to &&totnby&i;
&&pat&i&j
%end;
%mend symbol;
/* Create macro, GPLOT, that will produce graphs */
%macro gplot;
%do i=1 %to &total;
goptions reset=symbol;
%symbol
proc gplot data=icecream;
where grp="&&grp&i";
plot flavor * rank = z;
title1 h=1.25 f=swiss "Rankings, group &&grp&i";
run;
quit;
%end;
%mend gplot;
/* Call GPLOT macro */
%gplot

This samples uses macro variables to create SYMBOL statements that will maintain symbols across by values.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GPLOT Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Symbols/Interpolation
|
| Date Modified: | 2005-08-31 03:03:12 |
| Date Created: | 2004-11-11 11:07:59 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |