Sample 24892: Maintain patterns and midpoint ranges across BY values with PROC GMAP
This sample uses PROC GMAP and macro code to maintain patterns and midpoint ranges across BY values.
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 GMAP and macro code to maintain patterns and midpoint ranges across BY values.
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 the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;
/* Set macro debugging options */
options symbolgen mprint mlogic;
/* Create the 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
;
run;
/* 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;
/* Sort the data set by Z and 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=vibg'|| ' '||'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=depk'|| ' '||'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=mob'|| ' '||'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=grp'|| ' '||'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
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 GMAP and macro code to maintain patterns and midpoint ranges across BY values.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> GMAP
|
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 |