Professional Documents
Culture Documents
Maps Made Easy Using SAS Art Carpenters SAS Software by Mike Zdeb
Maps Made Easy Using SAS Art Carpenters SAS Software by Mike Zdeb
Maps Made Easy Using SAS Art Carpenters SAS Software by Mike Zdeb
/* */
/* Map Made Easy Using SAS */
/* by Mike Zdeb */
/* Copyright(c) 2002 by SAS Institute Inc., Cary, NC, USA */
/* SAS Publications order # 57495 */
/* ISBN 1-59047-093-1 */
/* */
/*-------------------------------------------------------------------*/
/* */
/* This material is provided "as is" by SAS Institute Inc. There */
/* are no warranties, expressed or implied, as to merchantability or */
/* fitness for a particular purpose regarding the materials or code */
/* contained herein. The Institute is not responsible for errors */
/* in this material as it now exists or will exist, nor does the */
/* Institute provide technical support for it. */
/* */
/*-------------------------------------------------------------------*/
/* */
/* Questions or problem reports concerning this material may be */
/* addressed to the author: */
/* */
/* SAS Institute Inc. */
/* Books by Users */
/* Attn: Mike Zdeb */
/* SAS Campus Drive */
/* Cary, NC 27513 */
/* */
/* If you prefer, you can send email to: sasbbu@sas.com */
/* Use this for subject field: */
/* Comments for Mike Zdeb */
/* */
/*-------------------------------------------------------------------*/
/* Date Last Updated: August 28, 2002 */
/*-------------------------------------------------------------------*/
/* */
/* Please NOTE... */
/* */
/* PART ONE of this file contains the SAS DATA steps that */
/* are shown in the Appendices of Maps Made Easy Using SAS. These */
/* DATA steps produce the data sets that are used in the examples. */
/* Create these data sets first so that your examples will run */
/* without problems. */
/* */
/* PART TWO of this file contains the SAS PROC steps that */
/* are shown in the book's examples. Each code segment is labeled */
/* with the chapter and example number.
/* */
/* Some examples in this file may differ slightly from the code */
/* presented in the book: */
/* */
/* A LEGEND statement may be added prior to PROC GMAP and a */
/* LEGEND option may be added to PROC GMAP in order to make the */
/* output conform to that displayed in the book. */
/* */
/* A GOPTIONS statement in Appendix C controls the appearance */
/* of text in some examples. It is added to examples when needed. */
/* */
/* A GOPTIONS statement in Example #3 of Chapter #3 reduces the */
/* overall size of the graphics output, resulting in the text in */
/* appearing close to the map as shown in the book. */
/* */
/* A GOPTIONS statement in Appendix C can be used to direct */
/* PROC GMAP output to a GIF file rather than the graphics output */
/* window. */
/* */
/* All current GOPTIONS settings are cleared prior to running */
/* each example by using the statement... GOPTIONS RESET=ALL; */
/* */
/*-------------------------------------------------------------------*/
/*****************************PART ONE********************************/
/*-------------------------------------------------------------------*/
/*--------------------------APPENDIX A-------------------------------*/
/*-------------------------------------------------------------------*/
data fip_func;
do fips_code = 1 to 95;
postal = fipstate(fips_code);
name_u = fipname(fips_code);
name_m = fipnamel(fips_code);
if name_u ne : 'INVALID' then output;
end;
label
fips_code = "FIPS CODE"
postal = 'POSTAL CODE'
name_u = 'UPPERCASE NAME'
name_m = 'MIXED CASE NAME'
;
run;
title 'FIPS CODES, POSTAL CODES, NAMES';
proc print data=fip_func noobs label;
run;
data st_func;
do fips = 1 to 79;
postal = fipstate(fips);
if postal ne '--' then do;
fips_code = stfips(postal);
sname_u = stname(postal);
sname_m = stnamel(postal);
output;
end;
end;
label
fips_code = "FIPS CODE"
postal = 'TWO-CHARACTER POSTAL CODE'
sname_u = 'UPPER CASE NAME'
sname_m = 'MIXED CASE NAME'
;
drop fips;
run;
title 'ST_FUNCTIONS';
proc print data=st_func noobs label;
run;
title;
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/*--------------------------APPENDIX D-------------------------------*/
/*-------------------------------------------------------------------*/
data font;
do i=0 to 100;
char=input(put(i,hex2.),$2.);
segment=1;
lp='p';
x=0; y=0; output;
y=i; output;
x=50; output;
y=0; output;
x=0; output;
segment=2;
lp='l';
x=0; y=0; output;
y=100; output;
x=50; output;
y=0; output;
x=0; output;
segment=3;
x=0; y=50; output;
x=-10; output;
segment=4;
x=60; y=50; output;
x=50; output;
end;
run;
libname gfont0 'i:\';
title 'THE GAUGE FONT';
proc gfont data=font name=gauge filled nokeymap codelen=2 height=3.5;
run;
title;
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/*--------------------------APPENDIX E-------------------------------*/
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/*--------------------------APPENDIX F-------------------------------*/
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/*--------------------------APPENDIX G-------------------------------*/
/*-------------------------------------------------------------------*/
data mapdatasets;
set maps.metamaps;
array var(13);
map = 0;
do j=1 to 13;
if var(j) eq 'SEGMENT' then map = 1;
if map eq 1 then leave;
end;
if map eq 1 then output;
run;
*** print the first 10 names;
proc print data=mapdatasets (obs=10) noobs;
var memname var1-var7;
run;
proc print data=maps.austria2;
run;
proc contents data=maps.uscenter;
run;
proc freq data=maps.uscity;
table featype / nopercent nocum;
run;
/*-------------------------------------------------------------------*/
/*****************************PART TWO********************************/
/*-------------------------------------------------------------------*/
/*----------------------------CHAPTER #1-----------------------------*/
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/*----------------------------CHAPTER #2-----------------------------*/
/*-------------------------------------------------------------------*/
proc gslide;
note 'NOTE LEFT-JUSTIFIED (DEFAULT)'
j=l 'NOTE LEFT-JUSTIFIED, NEW LINE CAUSED BY ANOTHER J=L'
move=(7,50) 'NOTE STARTED USING ABSOLUTE MOVE=(7,50)'
move=(7,-20) 'NOTE STARTED USING RELATIVE MOVE=(7,-20)'
move=(-65,-10) 'NOTE STARTED USING RELATIVE MOVE=(-65,-10)';
note 'NEW NOTE STATEMENT';
run;
quit;
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/*----------------------------CHAPTER #3-----------------------------*/
/*-------------------------------------------------------------------*/
* use the PROJECT procedure to project the combined state and county data
* set use two ID variables, STATE and COUNTY;
proc gproject
data=state_county
out=projected_counties
;
id state county;
run;
* select a font for all text and specify that all heights are expressed in
* percentages of the graphics output area;
goptions ftext='Arial/it/bo' gunit=pct;
* select two patterns for map areas - an empty (ME) pattern for states and a * s
olid (MS) pattern for counties;
pattern1 v=me c=black;
pattern2 v=ms c=grayc8;
* add descriptive text to the map with TITLE and FOOTNOTE statements;
title1 h=6 'COUNTIES WITH 25+% INCREASE IN POPULATION';
title2 h=5 '1990 TO 2000';
footnote j=l h=4 'US CENSUS BUREAU';
* use the GMAP procedure to create the map - use two ID variables, STATE and
* COUNTY;
proc gmap
map=projected_counties
data=projected_counties;
id state county;
choro dummy / discrete coutline=black nolegend;
run;
quit;
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/*----------------------------CHAPTER #1-----------------------------*/
/*-------------------------------------------------------------------*/
data anno;
retain
xsys ysys '2' function 'label'
style 'gauge' when 'a'
position '5' color 'black'
hsys '3' size 5
cbox 'white'
;
merge maps.uscenter
us2000st (where=(region in ('WEST','MIDWEST') and
fipstate(state) not in ('AK' 'HI'))
in=us2000);
by state;
if us2000;
x = long * constant('pi') / 180;
y = lat * constant('pi') / 180;
pct = 100 * (pop2000 - pop1990) / pop1990;
text = put(round(pct,1),hex2.);
run;
* combine selected observations from the MAPS.STATES data set with
* observations from the Annotate data set ANNO;
data map_anno;
set
maps.states (where=(fipstate(state) in ('AZ','CA','CO','ID','IL','IN','IA',
'KS','MI','MN','MO','MT','NE','NV',
'NM','ND','OH','OR','SD','UT','WA',
'WI','WY') and density le 2))
anno;
run;
* use the GPROJECT procedure to project the combined data set;
proc gproject data=map_anno out=projected;
id state;
run;
* separate the combined projected data set into a map data set (MAP)
* and an Annotate data set (ANNO);
data map anno;
set projected;
if when eq 'a' then output anno;
else output map;
run;
* select solid (MS) patterns for map areas, colors are shades of gray;
pattern1 v=ms c=grayfa;
pattern2 v=ms c=grayda;
pattern3 v=ms c=grayaa;
pattern4 v=ms c=gray5a;
* create a LEGEND;
legend1
origin=(60,5) pct mode=share shape=bar(3,4) across=2
label=(position=top h=3 'POPULATION (MILLIONS)') value=(j=l h=3);
* add descriptive text with TITLE statements;
title1 h=6 'YEAR 2000 CENSUS POPULATION';
title2 h=4 'GAUGE SHOWS % POPULATION CHANGE, 1990 TO 2000';
/*-------------------------------------------------------------------*/
/*----------------------------CHAPTER #5-----------------------------*/
/*-------------------------------------------------------------------*/
%macro manymaps;
%do i=1 %to 22;
%if &i eq 2 %then goptions gsfmode=append;;
%if &i eq 22 %then goptions gepilog='3B'x;;
data anno;
length text $40;
set pop (obs=&i) end=last;
if last then do;
size = 4;
text ='V';
call symput('year' ,year);
call symput('cost' ,location);
call symput('fips' ,put(fips,z3.));
end;
run;
title1 "CENTER OF US POPULATION: &YEAR";
title2 "&cost";
proc gmap
map=pmap
data=pmap (where=(state=&fips))
all;
id state;
choro state / discrete
nolegend
coutline=black
cempty=black
annotate=anno;
run;
quit;
%end;
%mend;
%manymaps;
/*-------------------------------------------------------------------*/