GREMOVE Procedure

Example 1: Removing State Boundaries from U.S. Map

Features:

BY statement

ID statement

Other features:

SORT procedure, MERGE statement, and LIBNAME statement

Sample library member: GRMUSMAP
This example processes the MAPS.US map data set, supplied with SAS/GRAPH, to produce a new map data set containing boundaries for the U.S. Bureau of the Census divisions. Because the MAPS.US map data set does not contain a variable to identify any unit area other than states, this example creates a map data set that contains the census divisions and that can be processed with the GREMOVE procedure.
The STATE variable in the MAPS.US data set, containing numeric FIPS codes for each state, is used as the BY-variable to merge the CBSTATES and MAPS.US data sets. The MAPS.US Data Set shows some of the variables that are present in the data set before using the GREMOVE procedure:
The MAPS.US Data Set
                              MAPS.US Data Set
               OBS    STATE    SEGMENT        X           Y

                 1      1          1       0.16175    -0.10044
                 2      1          1       0.12305    -0.10415
                 3      1          1       0.12296    -0.10678
                 .
                 .
                 .
              1524     56          1      -0.18757     0.15035
              1525     56          1      -0.10158     0.13997
              1526     56          1      -0.10398     0.11343
And Map Before Removing Borders shows the map before processing:
Map Before Removing Borders
Map before Removing Borders
The REMSTATE Data Set shows the variables that are present in the data set after you use the GREMOVE procedure. Notice that the new map data set contains a new variable called DIVISION:
The REMSTATE Data Set
                          REMSTATE Data Set
              OBS       X          Y       SEGMENT    DIVISION

                1    0.29825    0.17418       1           1
                2    0.29814    0.17820       1           1
                3    0.30206    0.18045       1           1
                .
                .
                .
             1082   -0.18715   -0.16010       8           9
             1083   -0.18747   -0.15971       8           9
             1084   -0.18747   -0.15951       8           9
Map After Removing Borders shows the new map after PROC GREMOVE has removed interior state boundaries.
Map After Removing Borders
Map after Removing Borders

Program

goptions reset=all border;
data cbstates;
   length state 8 stcode $ 2 division 4;
   input stcode division @@;
   state=stfips(stcode);
   drop stcode;
   datalines;
CT 1 MA 1 ME 1 NH 1 RI 1 VT 1 PA 2 NJ 2 NY 2 IL 3 IN 3 MI 3 OH 3 WI 3 IA 4 KS 4
MN 4 MO 4 ND 4 NE 4 SD 4 DC 5 DE 5 FL 5 GA 5 MD 5 NC 5 PR 5 SC 5 VA 5 WV 5
AL 6 KY 6 MS 6 TN 6 AR 7 LA 7 OK 7 TX 7 AZ 8 CO 8 ID 8 MT 8 NM 8 NV 8 UT 8
WY 8 AK 9 CA 9 HI 9 OR 9 WA 9
;
proc sort data=cbstates out=cbsort;
   by state;
run;
data uscb;
   merge cbsort maps.us;
   by state;
run;
proc sort data=uscb out=divstate;
   by division;
run;
proc gremove data=divstate out=remstate;
   by division;
   id state;
run;
title "U.S. State Map";
footnote j=r "GRMUSMAP(a) ";
pattern value=mempty color=blue;
proc gmap map=maps.us data=maps.us all;
   id state;
   choro state / nolegend levels=1;
run;
title "U.S. Census Division Map";
footnote j=r "GRMUSMAP(b) ";
proc gmap map=remstate data=remstate all;
   id division;
   choro division / nolegend levels=1;
run;
quit;

Program Description

Set the graphics environment.
goptions reset=all border;
Create data set CBSTATES. This data set includes a variable, DIVISION, that contains the number of the U.S. Bureau of the Census division for the state. This DATA step converts letter codes to numeric FIPS codes that match those in the STATE variable of MAPS.US.
data cbstates;
   length state 8 stcode $ 2 division 4;
   input stcode division @@;
   state=stfips(stcode);
   drop stcode;
   datalines;
CT 1 MA 1 ME 1 NH 1 RI 1 VT 1 PA 2 NJ 2 NY 2 IL 3 IN 3 MI 3 OH 3 WI 3 IA 4 KS 4
MN 4 MO 4 ND 4 NE 4 SD 4 DC 5 DE 5 FL 5 GA 5 MD 5 NC 5 PR 5 SC 5 VA 5 WV 5
AL 6 KY 6 MS 6 TN 6 AR 7 LA 7 OK 7 TX 7 AZ 8 CO 8 ID 8 MT 8 NM 8 NV 8 UT 8
WY 8 AK 9 CA 9 HI 9 OR 9 WA 9
;
Sort data set in FIPS-code order. Create a sorted data set, CBSORT. It can be properly match-merged with the MAPS.US map data set, which is already sorted in FIPS-code order.
proc sort data=cbstates out=cbsort;
   by state;
run;
Add DIVISION variable to map data set by merging the CBSORT data set with MAPS.US. Create a new map data set, USCB, that contains all of the state boundary coordinates from the MAPS.US data set plus the added variable DIVISION.
data uscb;
   merge cbsort maps.us;
   by state;
run;
Sort data set in DIVISION order. Sort USCB by the DIVISION variable to create the DIVSTATE data set.
proc sort data=uscb out=divstate;
   by division;
run;
Remove interior boundaries within divisions. BY specifies the variable, DIVISION, in the input map data set that identifies the new unit areas. ID specifies the variable, STATE, in the input map data set that identifies the current unit areas.
proc gremove data=divstate out=remstate;
   by division;
   id state;
run;
Define title and footnote for map.
title "U.S. State Map";
footnote j=r "GRMUSMAP(a) ";
Define pattern characteristics.
pattern value=mempty color=blue;
Show the original map.
proc gmap map=maps.us data=maps.us all;
   id state;
   choro state / nolegend levels=1;
run;
Define new title and footnote for map.
title "U.S. Census Division Map";
footnote j=r "GRMUSMAP(b) ";
Show the regional map. ID specifies the variable, DIVISION, that identifies the unit areas in the processed data set. CHORO specifies DIVISION as the response variable.
proc gmap map=remstate data=remstate all;
   id division;
   choro division / nolegend levels=1;
run;
quit;