Previous Page | Next Page

The GMAP Procedure

Using SAS/GRAPH Map Data Sets


Accessing Detailed Descriptions of Map Data Sets

You might need detailed information on the map data sets in order to determine their type, size, the variables they contain, or, in the case of traditional data sets, whether they are projected or unprojected. You can get this information by using the CONTENTS or DATASETS procedure, or browsing the MAPS.METAMAPS (see The METAMAPS Data Set) data set in the MAPS library (or the library where your SAS-supplied map data sets reside). If the libref MAPS has automatically been assigned, you can see a complete list of map data sets by viewing the MAPS.METAMAPS data set.

These statements list the map data sets in the SAS library that is assigned to the libref MAPS:

proc datasets lib=maps;
run;

The following statements provide detailed information on a traditional 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 supplied by SAS you can specify DATA=MAPS._ALL_ in the CONTENTS procedure. See the Base SAS Procedures Guide for more information on the CONTENTS and DATASETS procedures.


Customizing SAS/GRAPH 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.

With the traditional map data set, you can also use the GPROJECT procedure to create a rectangular subset of a map data set by using minimum and maximum longitude and latitude values. For more information, see The GPROJECT Procedure.

You can combine traditional map data sets in either of these situations:

Traditional 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.


Subsetting Traditional 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 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 traditional map data set, begin the GMAP procedure with this statement:

proc gmap map=maps.canada(where=(province="24"));

To use only North Carolina in US2MERGED (a data set created by using SQL or DATA step MERGE on the feature table US2 and a response data set also containing the variable STATE) the GMAP procedure would begin with the following statement:

proc gmap data=work.us2merged(where=(STATE=37));

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 traditional map data set and the response data sets or the merged response and feature table.

Another approach is to use a DATA step to create a subset of the larger data set. This code illustrates another way to extract the observations for Quebec from the CANADA traditional map data set:

data quebec;
   set maps.canada(where=(province="24"));

This code illustrates another way to extract North Carolina data from the US2 feature table:

data ncarolina;
   set maps.us2(where=(STATE=37));

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 The GREMOVE Procedure for an example of how to use GREMOVE to create a regional map from one of the traditional map data sets that are supplied with SAS/GRAPH.


Reducing Traditional 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 traditional 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 The GREDUCE Procedure.

Note:   Many of the map data sets in the MAPS library are supplied with a DENSITY variable.  [cautionend]

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, so 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 on 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

Map data can be stored as unprojected or projected coordinates. Unprojected map data contains spherical coordinates, that is, longitude and latitude values usually expressed in radians.(footnote 1)

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.

If the projection supplied with the traditional 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 on traditional map data sets with unprojected coordinates, see Traditional 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 The GPROJECT Procedure for more information.

Note:   Using an unprojected traditional map data set with the GMAP procedure can cause your map to be reversed.  [cautionend]


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 traditional 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.

Traditional map data sets that contain coordinates for a lake that is located within a single internal division are identified by the presence of the numeric variable LAKE. The value of LAKE is 1 for points that correspond to lakes and 0 otherwise. 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 nolegend;
   title box=1 f=none h=4
         "Chile with Lakes Removed";
run;

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;


Creating Traditional Map Data Sets

In addition to using map data sets that are supplied with SAS/GRAPH software, you can also create your own map data sets. Map data sets are not limited to geographic data; you use them to define other spaces such as floor plans.

A unit area is defined by observations in the map data set that have the same identification (ID) variable value. A unit area might be composed of a single polygon or a collection of polygons. A polygon is defined by all of the observations that have the same SEGMENT variable value within the same unit area.


Creating a Unit Area that is a Single Polygon

This DATA step creates a SAS data set that contains coordinates for a unit area with a single polygon, a square:

data square;
   input id x y;
   datalines;
1 0 0
1 0 40
1 40 40
1 40 0
;

This data set does not have a SEGMENT variable.


Creating a Unit Area that Contains Multiple Polygons

Use different values of the SEGMENT variable to create separate polygons within a single unit area. For example, this DATA step assigns two values to the SEGMENT variable. The resulting data set produces a single unit area that contains two polygons, as shown in Single Unit Area with Two Segments (Polygons):

data map;
   input id $ segment x y;
   datalines;
square   1 0 0
square   1 0 4
square   1 4 4
square   1 4 0
square   2 5 5
square   2 5 7
square   2 7 7
square   2 7 5
;

Single Unit Area with Two Segments (Polygons)

[Single Unit Area with Two Segments (Polygons)]


Creating a Unit Area that Contains Enclosed Polygons as Holes

Use separate boundaries to create an enclosed polygon (that is, a polygon that falls within the primary polygon for a single segment). The boundary for the hole is separated from the primary polygon boundary by inserting a missing value for X and Y. For example, the data set that is created by this DATA step produces the map shown in Single Unit Area with Hole:

data map;
   input id $ segment x y;
   datalines;
square   1 0 0
square   1 0 4
square   1 4 4
square   1 4 0
square   1 . .
square   1 1 1
square   1 2 2
square   1 3 1
;

Single Unit Area with Hole

[Single Unit Area with Hole]

Note:   A single map segment (a section of a unit area with a single value of the SEGMENT variable) cannot contain multiple polygons without at least one observation with missing values for X and Y. All segments within the map data sets that are supplied by SAS/GRAPH contain a single polygon that can have one or more separate boundaries, each separated by an observation with missing values for X and Y.  [cautionend]


Creating a Unit Area that Contains Another Area

Sometimes rather than a hole or lake, an enclosed polygon represents a separate map area. For example, in MAPS.AFRICA, the country of Lesotho is surrounded by the country of South Africa.

To create an enclosed map area:

  1. Create an observation with missing values for X and Y for the surrounding area.

  2. Define the boundary as part of the surrounding area by the using ID value for the surround area.

  3. Define the boundary as part of the enclosed area by using the ID value for the enclosed area.

For example, this DATA step creates a data set that produces the map shown in Unit Area within a Unit Area:

data map;
   input id $ segment x y;
   datalines;
square   1 0 0
square   1 0 4
square   1 4 4
square   1 4 0
square   1 . .
square   1 1 1
square   1 2 2
square   1 3 1
triangle 1 1 1
triangle 1 2 2
triangle 1 3 1
;

Unit Area within a Unit Area

[Unit Area within a Unit Area]


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]. [arrow]

Previous Page | Next Page | Top of Page