GMAP Procedure

Using SAS/GRAPH Map Data Sets

Specifying the Location of Map Data Sets

There are three library references (librefs) associated with the location of a SAS library; each library containing map data sets used by SAS/GRAPH. The three are as follows:
  • MAPS
  • MAPSGFK
  • MAPSSAS
MAPS references the library containing the latest set of SAS traditional maps. This library is defined in a configuration file with the value set to the same physical name (path) as MAPSSAS. In the following example, MAPS is the libref, and UK is a file in the SAS MAPS library.
MAPS.UK
The libref is assigned through the MAPS= System Option. It can also be set or changed with a LIBNAME statement, which enables each client to set their own definition for MAPS. This client setting would override the server setting defined at start-up time. Note that using the APPEND= System Option in SAS System Options: Reference or theINSERT= System Option in SAS System Options: Referencewith the MAPS= System Option allows an additional libref to be assigned to MAPS without changing its original definition. In this way existing programs can reference either the latest SAS or the MAPSGFK digital, vector map data sets.
MAPSGFK references the library containing the digital, vector map data sets at a location separate from the latest non-digital, vector SAS map data sets. This library is defined in a configuration file as a single physical path. This definition is set at installation time and should not be changed. The libref is assigned through the MAPSGFK= System Option.
MAPSSAS references the library containing the latest set of SAS traditional map files. This library is defined in a configuration file as a single physical name (path). It is the same path that MAPS references. This definition is set at installation time and should not be changed. The libref is assigned through the MAPSSAS= System Option.

Accessing Detailed Descriptions of Map Data Sets

You might need detailed information about the map data sets in order to determine their type, size, the variables that they contain, or, in the case of traditional map data sets, whether they are projected or unprojected. You can get this information by doing the following:
  • using the CONTENTS or DATASETS procedure
  • browsing the MAPS.METAMAPS data set in the MAPS library
  • browsing the MAPSSAS.METAMAPS data set in the MAPSSAS library.
  • browsing the library where your map data sets supplied by SAS reside
See The METAMAPS Data Set. Once the libref MAPS has been assigned, you can see a complete list of map data sets by viewing the MAPS.METAMAPS data set.
Run the following statements to list the map data sets in the SAS library that is assigned to the libref MAPS:
proc data sets lib=maps;
run;
Alternatively, you can substitute the libref MAPSGFK or MAPSSAS.
Run the following statements to provide detailed information about a map data set, including the number of observations, the variables in each data set, and a description of each variable:
proc contents data=maps.canada3;
run;
To see the contents and descriptions of all of the map data sets associated with one of the three map libraries supplied by SAS, specify one of the following statements in the CONTENTS procedure:
  • DATA=MAPS._ALL_
  • DATA=MAPSSAS._ALL_
  • DATA=MAPSGFK._ALL_
See the Base SAS Procedures Guide for more information about the CONTENTS and DATASETS procedures..

Customizing SAS/GRAPH Map Data Sets

Overview of Customizing Map Data Sets

You can customize the area that is displayed on your map by using only part of a particular map data set. There are several ways to accomplish this. You can use WHERE processing or a DATA step to subset the map data to be used by the GMAP procedure.
You can also use the GPROJECT procedure with the map data set to create a rectangular subset of a map data set. Do this by using the minimum and maximum longitude and latitude values in the map data set. For more information, see GPROJECT Procedure.
You can combine map data sets in either of these situations:
  • The map data sets to be combined were originally projected together.
  • The map data sets all contain the same type of coordinates. That is, all are in radians or all are in degrees, and the longitude coordinates are measured in the same direction.
Map data sets supplied by SAS that have coordinates expressed only as longitude and latitude, with variable names LONG and LAT, must be renamed X and Y and should be projected before you use them with the GMAP procedure. Map data sets from GfK GeoMarketing GmBH already contain projected coordinates expressed as longitude and latitude in degrees, with variable names LONG and LAT.

Subsetting Map Data Sets

Some of the SAS/GRAPH map data sets contain a large number of observations. Programs that use only a few states or provinces run faster if you exclude the unused portion of the map data set or use a reduced map data set. SAS provides several ways to accomplish this. One is to use the WHERE statement or WHERE= data set option within the GMAP procedure to select only the states or provinces that you want.
The WHERE statement and WHERE= data set option are most useful when you produce a simple map and do not need to make any other changes to the data set. For example, to use only the observations for Quebec in the CANADA map data set, begin the GMAP procedure with this statement:
proc gmap map=maps.canada(where=(province="24"));
The WHERE= data set option applies only to the data set that you specify in the argument in which the WHERE= option appears. If you use the WHERE statement, the WHERE condition applies to the map data set and the response data set.
Another approach is to use a DATA step to create a subset of the larger data set. This code illustrates a way to extract the observations for Quebec from the CANADA map data set:
data quebec;
   set maps.canada(where=(province="24"));
This approach is most useful when you want to create a permanent subset of a map data set or when you need to make additional changes to the map data set.
Also see GREMOVE Procedure for an example of how to use GREMOVE to create a regional map from one of the map data sets that are supplied with SAS/GRAPH.

Reducing Map Data Sets

A reduced map data set is one that can be used to draw a map that retains the overall appearance of the original map but that contains fewer points, requires considerably less storage space, and can be drawn much more quickly. You can improve performance by plotting fewer observations for each map area. You reduce a map data set when you subset it on the variable DENSITY. You can add the variable DENSITY to a map data set by using the GREDUCE procedure. For more information, see GREDUCE Procedure.
Note: Many of the map data sets in the MAPS library are supplied with a DENSITY variable.
An unreduced map data set contains all of the coordinates that were produced when the map was digitized. This type of map data set has more observations than most graphics output devices can accurately plot. Some unreduced map data sets already contain a DENSITY variable like the one calculated by the GREDUCE procedure. Therefore, it is not necessary to use the GREDUCE procedure to process these data sets. Values for DENSITY range from 0 through 6 (the lower the density, the coarser the boundary line).
You can set the DENSITY value by using the DENSITY= option in the PROC GMAP statement. For example, the following statement excludes all points with a density level of 2 or greater:
proc gmap map=maps.states density=2;
The resulting map is much coarser than one drawn by using all of the observations in the data set, but it is drawn much faster.
Another way to create a reduced map data set is to use a DATA step to exclude observations with larger density values:
data states;
   set maps.states(where=(density<2));

Projecting Traditional Map Data Sets

Traditional map data can be stored as unprojected or projected coordinates. GfK map data is stored as only projected. Unprojected map data contains spherical coordinates, that is, longitude and latitude values usually expressed in radians.(footnote1)
Many of the map data sets in the MAPS library are projected. However, these map data sets contain only unprojected coordinates and should be projected before you use them.
  • CANADA3
  • CANADA4
  • COUNTIES
  • COUNTY
  • STATES
If the projection supplied with the map data set does not meet your needs, then you can use the GPROJECT procedure (on unprojected map coordinates) to create a different projection. For more information about map data sets with unprojected coordinates, see Map Data Sets Containing X, Y, LONG, and LAT. You should select a projection method that least distorts the regions that you are mapping. (All projection methods inherently distort map regions.) See GPROJECT Procedure for more information.
Note: Using an unprojected map data set with the GMAP procedure can cause your map to be reversed.

Controlling the Display of Lakes

Some countries contain a lake that is located completely within a single unit area. Occasionally these lakes can be a problem when mapping map data sets. In addition, displaying lakes might not be appropriate for some applications. In these cases, you might want to remove the lakes from the map data set before you proceed.
In traditional and GfK map data sets that contain coordinates for a lake that is located within a single internal division, the lake is identified with the numeric variable LAKE. The value of LAKE is 1 for points that correspond to lakes and 0 otherwise. STAT=FIRST processes only the first observation that matches the geographic region. The following statements illustrate how to delete the lakes from your traditional map data sets using WHERE processing:
proc gmap map=maps.chile(where=(lake=0))
          data=maps.chile;
   id id;
   choro id / levels=1 stat=first nolegend;
   title box=1 f=none h=4
         "Chile with Lakes Removed";
run;
quit;
The following statements illustrate how to delete the lakes from your GfK map data sets using WHERE processing:
proc gmap map=mapsgfk.us_all(where=(lake=0))
          data=mapsgfk.us_all;
   id id;
   choro id / levels=1 stat=first nolegend;
   title box=1 f=none h=4
         "U.S. with Lakes Removed";
run;
quit;
You can also create a new traditional map data set that is a subset of the traditional map data set:
data nolake;
   set maps.chile(where=(lake=0));
run;
FOOTNOTE 1:If your data is in degrees, then it can be converted to radians by multiplying by the degree-to-radian constant [atan(1)/45].[return]