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 States on a United States Map */

/* Set graphics options */

goptions reset=global ftext=zapfi htext=4 gunit=pct
cback=white colors=(black) border;

/******************************************************************/
/* Create the response data set, POP. The data for POP contains   */
/* state abbreviations (ST) and the percent of population change  */
/* for each state (CHANGE). The STFIPS function converts the      */
/* two-letter postal codes to numeric FIPS codes (STATE) that can */
/* be used as an identification variable with the map data set,   */
/* MAPS.USCENTER.                                                 */
/******************************************************************/

data pop(drop=st);
input st $ change @@;
state=stfips(st);
cards;
AL 3.8  AK 36.9 AZ 34.8 AR 2.8  CA 25.7
CO 14.0 CT 5.8  DE 12.1 FL 32.7 GA 18.6
HI 14.9 ID 6.7  IL 0.0  IN 1.0  IA -4.7
KS 4.8  KY 7.0  LA 0.3  ME 9.2  MD 13.4
MA 4.9  MI 0.4  MN 7.3  MS 2.1  MO 4.1
MT 1.6  NE 0.5  NV 50.1 NH 20.5 NJ 5.0
NM 16.3 NY 2.5  NC 12.7 ND -2.1 OH 0.5
OK 4.0  OR 7.9  PA 0.1  RI 5.9  SC 11.7
SD 0.8  TN 6.2  TX 19.4 UT 17.9 VT 10.0
VA 15.7 WA 17.8 WV -8.0 WI 4.0  WY -3.4
;

/*****************************************************************/
/* Create the Annotate data set, MAPLABEL, from MAPS.USCENTER.   */
/* MAPLABEL labels each state with a two-letter abbreviation.    */
/* MAPS.USCENTER provides the x and y coordinates for the labels */
/* FLAG, which is initially turned off, signals when external    */
/* labeling is in effect. The labels are drawn after the map     */
/* because the value of WHEN is a (after).                       */
/*****************************************************************/

data maplabel;
length function $ 8;
retain flag 0 xsys ysys '2' hsys '3' when 'a' style 'swissb';
set maps.uscenter(where=(fipstate(state) ne 'DC') drop=long lat);

function='label'; text=fipstate(state); size=2.5; position='5';

/* The FIPSTATE function creates the label   */
/* text by converting the FIPS codes from    */
/* MAPS.USCENTER to two-letter postal codes. */

if ocean='Y' then
do;
position='6'; output;
function='move';
flag=1;
end;

/* If the labeling coordinates are outside the state (OCEAN='Y'), Annotate    */
/* adds the label and prepares to draw the leader line. Note: OCEAN is a      */
/* character variable and is therefore case sensitive. OCEAN='Y' must specify */
/* an uppercase Y.                                                            */

/* When external labeling is in effect, Annotate */
/* draws the leader line and resets the flag.    */
else if flag=1 then
do;
function='draw'; size=.5;
flag=0;
end;
output;
run;
/* Create a format for the value of CHANGE. The PCHANGE. */
proc format;
value pchange   low - -0.01 = 'Decrease'   /* format asssociates descriptive labels with ranges of */
0.0 - 5     = 'Up 0 to 5%'  /* population values.                                  */
5.01 - 10    = 'Up 5 to 10%'
10.01 - 20    = 'Up 10 to 20%'
20.01 - 30    = 'Up 20 to 30%'
30.01 - high  = 'Up over 30%';
run;

/****************************************************************/
/* Define patterns for the map.  Pattern colors are gray-scale  */
/* values ranging from GRAY44 (dark gray) to GRAYFF (white).    */
/* Because patterns are assigned in order to response values,   */
/* beginning with the lowest value, the patterns are ordered    */
/* from lightest to darkest, so that white represents the least */
/* change and dark gray the most.                               */
/****************************************************************/

pattern1 value=solid color=grayff;    /* white */
pattern2 value=solid color=grayee;
pattern3 value=solid color=graycc;
pattern4 value=solid color=gray99;
pattern5 value=solid color=gray77;
pattern6 value=solid color=gray44;    /* dark gray */

/*****************************************************************/
/* Add titles and footnotes. The null FOOTNOTE3 statement shifts */
/* the map left to make room for the legend.                     */
/*****************************************************************/

title1 height=6 'Change in Population between 1980 and 1990';
footnote1 justify=left ' Source: U.S. Bureau of Census';
footnote2 font=swissl height=2.5 justify=left ' SAS/GRAPH' move=(+0,+.5) '02'x
move=(+0,-.5) ' Software' justify=right 'POP ';
footnote3 height=10 angle=90 ' ';

/***********************************************************************/
/* Modify the position and appearance of the legend. ACROSS=1 places   */
/* the entries in a single column. ORIGIN= positions the legend to     */
/* the right of the map.  MODE=SHARE allows the legend to occupy space */
/* allocated to the map.                                               */
/***********************************************************************/

legend1 label=none shape=bar(4,3) value=(height=2) across=1 origin=(78,18)
mode=share;

/************************************************************************/
/* Produce the map. The CHORO statement includes the annotation defined */
/* in the MAPLABEL data set.  DISCRETE is added so that each formatted  */
/* value of CHANGE is treated as a separate response level.             */
/************************************************************************/

proc gmap data=pop map=maps.us;
format change pchange.;
id state;
choro change / legend=legend1 discrete coutline=black annotate=maplabel;
run;
quit;