Sample 24892: Maintain patterns and midpoint ranges across BY values
/* Maintain patterns and midpoint ranges across BY values. */
/* Set macro variable options */
options macrogen symbolgen mprint mlogic;
/* Set graphics options */
goptions reset=all border;
/* Create input data set, ONE */
data one;
input state sites z $;
datalines;
10 100 1
20 300 1
30 600 1
40 900 1
10 110 2
30 610 2
40 910 2
10 120 3
20 320 3
40 920 3
10 130 4
20 330 4
30 630 4
40 930 4
;
/* Be careful with the PROC FORMAT section. If you run this program from the */
/* program editor, be aware that once the format has been created in the */
/* temporary library, WORK, if you change the format values without exiting */
/* the program editor, or somehow clear the format definitions, then SAS */
/* will use the formats prior to the change. */
/* */
/* To easily get around this problem, simply comment out the PROC FORMAT */
/* section once the proper format has been defined. */
proc format;
value xform 0-250 = '0 to 250'
251-500 = '251 to 500'
501-750 = '501 to 750'
751-999 = '751 to 999';
run;
/* Sorting by the by-group variable, SITES */
proc sort;
by z sites;
run;
/* Create the input data set, NEW */
data new;
set one end=eof;
by z sites;
if first.z then do;
bycount=0;
total+1;
end;
bycount+1;
/* Creates the by group macro variables used in WHERE statement */
call symput('z'||left(total),z);
/* Conditionally assigning the patterns. */
if state = 10 then do;
call symput('pat'||trim(left(total))||trim(left(bycount)),
'pattern'||trim(left(total))||trim(left(bycount))
|| ' '|| 'c=blue'|| ' '||'v=solid'||' '||';');
end;
if state = 20 then do;
call symput('pat'||trim(left(total))||trim(left(bycount)),
'pattern'||trim(left(total))||trim(left(bycount))
|| ' '|| 'c=cyan'|| ' '||'v=solid'||' '||';');
end;
if state = 30 then do;
call symput('pat'||trim(left(total))||trim(left(bycount)),
'pattern'||trim(left(total))||trim(left(bycount))
|| ' '|| 'c=green'|| ' '||'v=solid'||' '||';');
end;
if state = 40 then do;
call symput('pat'||trim(left(total))||trim(left(bycount)),
'pattern'||trim(left(total))||trim(left(bycount))
|| ' '|| 'c=red'|| ' '||'v=solid'||' '||';');
end;
if last.z then call symput('totnby'||trim(left(total)),bycount);
if eof then call symput('total',total);
run;
/* The PATTERN macro is creating all the pattern */
/* statements to be used across the BY groups. */
%macro pattern;
%do j=1 %to &&totnby&i;
&&pat&i&j
%end;
%mend pattern;
/* The GMAP macro calls the PATTERN macro which contains the */
/* GMAP procedure to create multiple graphs. The WHERE */
/* statement is performing the function that the BY statement */
/* would have provided. The BY statement is not used, because */
/* we need to increment the macro variable Z using the */
/* counter variable (i) in a %DO loop. */
%macro gmap;
%do i=1 %to &total;
goptions reset=pattern;
%pattern
proc gmap map=maps.us data=one all;
where z="&&z&i";
title "Group &&z&i";
format sites xform.;
id state;
choro sites / coutline=black discrete;
run;
quit;
%end;
%mend gmap;
%gmap

This sample uses macro coding to produce pattern statements based on the value of the BY group.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GMAP Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Patterns
|
| Date Modified: | 2005-08-24 16:06:30 |
| Date Created: | 2004-11-11 11:07:56 |
Operating System and Release Information
| SAS System | SAS/GRAPH | All | n/a | n/a |