Sample 24891: Labeling cities on a United States map with PROC GMAP
This sample uses PROC GMAP and the Annotate facility to label cities on a map. The sample code creates the Annotate data set by locating the 'X' using city coordinates from MAPS.USCITY. Each line of the stacked label is positioned around the 'X'
by using the coordinates for the city and adjusting the alignment to that point.
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 the Annotate facility to label cities on a map. The sample code creates the Annotate data set by locating the 'X' using city coordinates from MAPS.USCITY. Each line of the stacked label is positioned around the 'X' by using the coordinates for the city and adjusting the alignment to that point.
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;
/* Create the input data set, AIRPRTS. AIRPRTS provides the */
/* name of the airport, the city and state in which it is */
/* located, and the number of passengers that used the airport. */
data airprts(drop=st);
input st $2. city $25. airport $20. passngrs comma12.;
state=stfips(st);
datalines;
IL Chicago O'Hare Int'l 21,841,000
GA Atlanta Hartsfield Int'l 17,472,000
CA Los Angeles International 15,298,000
NY New York J.F.K. 11,975,000
CA San Francisco International 11,247,000
;
run;
/* Create a format for the values of PASSNGRS. Q and R from the */
/* MARKER font select male and female symbols, respectively. The */
/* format, PASSFMT., adds a symbol for every 5 million passengers.*/
proc format;
value passfmt 1000000-5000000='Q'
5000001-10000000='QR'
10000001-15000000='QRQ'
15000001-20000000='QRQR'
20000001-25000000='QRQRQ';
run;
/* Sort AIRPRTS by STATE and CITY. The data in AIRPRTS will be */
/* merged with the coordinates in MAPS.USCITY, so AIRPRTS must be */
/* sorted in the same order that MAPS.USCITY is sorted. */
proc sort data=airprts;
by state city;
run;
/* Create the AIRPRTS data set. Merge the city coordinates from */
/* MAPS.USCITY with the data in AIRPRTS. IN= and the IF statement */
/* select only the cities from MAPS.USCITY that are in AIRPRTS. */
data airprts2(keep=city airport passngrs x y);
merge airprts(in=inair) maps.uscity;
by state city;
if inair;
run;
/* Create the Annotate data set, LABELS. LABELS adds the labels for */
/* the airports. X and Y from MAPS.USCITY provide the coordinates, */
/* for the city. Since the values of X and Y are map coordinates, XSYS */
/* and YSYS must be absolute data values(2). WHEN=a causes the annotation */
/* to overlay the map. */
data labels(drop=city airport passngrs);
length function color $ 8 text $ 25 style $ 25;
retain function 'label' xsys ysys '2' hsys '3' when 'a';
/* The values of the CITY, AIRPORT, and PASSNGRS variables from AIRPRTS2 */
/* determine the text of the labels. The formatted value of PASSNGRS */
/* displays rather than the number itself. */
set airprts2;
text='X'; style="'Albany AMT/bold'";
color='depk'; size=4; position='5'; output;
text=' '||city; style="'Albany AMT'";
color='black'; size=3; position='3'; output;
text=' '||airport; position='6'; output;
text=' '||put(passngrs,passfmt.); position='9';
style='marker'; size=4; output;
run;
/* Add a title to the graph */
title1 'Busiest Airports in the U.S.';
footnote1 h=2 ' ';
/* Define the pattern for the map areas */
pattern1 value=msolid color=CX7C95CA repeat=49;
/* Produce the choropleth map of the continental US. The map data set is */
/* used as the respnse data set. The NOTE statement provides a legend for */
/* the symbols. The CHORO statement includes the annotation defined in */
/* the LABELS data set. */
proc gmap data=maps.us map=maps.us;
note move=(10pct,10pct) font=marker 'Q' font="Albany AMT" '= 5 million people';
id state;
choro state / discrete xsize=95 pct
nolegend coutline=gray88 annotate=labels;
where fipstate(state) not in ('AK' 'HI' 'PR');
run;
quit;
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.
The Annotate facility is used to label the map. The city coordinates are obtained from the MAPS.USCITY data set. Each line of the stacked label is positioned around the 'X' by using the coordinates for the city and adjusting the alignment to that point.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> GMAP Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Annotation
|
Date Modified: | 2005-08-24 16:06:30 |
Date Created: | 2004-11-11 11:07:55 |
Operating System and Release Information
SAS System | SAS/GRAPH | All | n/a | n/a |