Maps Online >Resources SAS logo
Feedback   

Sample Data
Sample Programs
Tools
Useful Links

/*******************************************************************\
| Copyright (C) 1998 by SAS Institute Inc., Cary, NC, USA.          |
|                                                                   |
| SAS (R) is a registered trademark of SAS Institute Inc.           |
|                                                                   |
| SAS Institute does not assume responsibility for the accuracy of  |
| any material presented in this file.                              |
\*******************************************************************/


/************************************************************/
/* Labeling Cities on a United State Map                    */
/*                                                          */
/* The Annotate facility labels the map. Annotate locates   */
/* 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.                                 */
/************************************************************/

/* Set the graphics options */

goptions reset=global cback=white colors=(black) border
htext=3 gunit=pct;

/****************************************************************/
/* 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);
cards;
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
;

/******************************************************************/
/* 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;
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='swissb'; color='gray66'; size=4; position='5'; output;
text=' '||city; style='swiss'; color='black'; size=2.5; position='3'; output;
text=' '||airport; position='6'; output;
text=' '||put(passngrs,passfmt.); position='9';
style='marker'; size=3.75; output;
run;

/* Add titles and footnotes */

title1 font=swissb height=6 'Busiest Airports in the U.S.';
footnote1 font=swissl height=2.5 justify=left ' SAS/GRAPH'
move=(+0,+.5) '02'x move=(+0,-.5) ' Software'
justify=right 'AIRPORTS ';

/* Define the pattern for the map areas */

pattern1 value=msolid color=graydd 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=(10,15) font=marker 'Q' font=swiss '= 5 million people';
id state;
choro state / discrete xsize=95 pct
nolegend coutline=gray88 annotate=labels;
where fipstate(state) not in ('AK' 'HI');
run;
quit;