GMAP Procedure

Creating SAS Map Data Sets

Creating Map Data Sets

Overview

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.
When creating map data sets with geographic data, the following variables must be included:
  • a numeric variable named X that contains the horizontal coordinates of the boundary points. The value of this variable is projected and represents longitude. This variable is required by the GMAP procedure.
  • a numeric variable named Y that contains the vertical coordinates of the boundary points. The value of this variable is projected and represents latitude. This variable is required by the GMAP procedure.
  • one or more variables that uniquely identify the areas in the map. Map area identification variables can be either character or numeric and are indicated in the ID statement. An identification variable is required by the GMAP procedure.
The X and Y variable values in the GfK map data set do not have to be in any specific units. They are rescaled by the GMAP procedure based on the minimum and maximum values in the data set. The minimum X and Y values are in the lower left corner of the map, and the maximum X and Y values are in the upper right corner.
The GMAP procedure uses the values of the X and Y variables to draw the map. To use the unprojected values to produce a custom map, follow the tasks in Map Data Sets Containing X, Y, LONG, and LAT.
Map data sets in which the X and Y variables contain longitude and latitude should be projected before you use them with PROC GMAP. See GPROJECT Procedure for details.
Other variables to consider including in map data sets are:
  • a numeric variable named DENSITY that holds the density values returned from a GREDUCE procedure.
  • a numeric variable named LONG that contains the horizontal coordinate of the boundary point in degrees. The value of this variable is unprojected and represents longitude (east-west position).
  • a numeric variable named LAT that contains the vertical coordinate of the boundary point in degrees. The value of this variable is unprojected and represents latitude (north-south position).
  • a variable named SEGMENT to identify map areas that comprise noncontiguous polygons. Each unique value of the SEGMENT variable within a single map area defines a distinct polygon. If the SEGMENT variable is not present, each map area is drawn as a separate closed polygon that indicates a single segment.
    The observations for each segment of a map area in the map data set must occur in the order in which the points are to be joined. The GMAP procedure forms map area outlines by connecting the boundary points of each segment in the order in which they appear in the data set. Eventually the last point is joined to the first point to complete the polygon. All the segments for each ID value must be contiguous within the map data set.
  • a variable named RESOLUTION to map detail level based on output resolution. Refer to RESOLUTION Variable Values for a list of the output resolutions associated with a RESOLUTION variable value.
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.
  • If the unit area is a single polygon, then all values of SEGMENT are the same (alternatively, you can omit the SEGMENT variable).
  • If the unit area contains multiple polygons, such as islands, then the SEGMENT variable has multiple values. For example, in the MAPS.US data set, the state of Hawaii (a unit area) contains six different values in the SEGMENT variable, one for each island in the state.
  • If the unit area contains enclosed polygons (holes), such as lakes, then the SEGMENT variable has one value but the interior polygon is defined by separate boundaries. To separate boundaries, a missing X and Y value must be inserted at the separation point. For example, in the CANADA2 data set supplied with SAS/GRAPH, the map data for the Northwest Territories (a unit area) use enclosed polygons for two lakes.

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 is a section of a unit area with a single value of the SEGMENT variable. A single map segment cannot contain multiple polygons without having at least one observation with missing values for X and Y. All segments within map data sets supplied by SAS/GRAPHcontain a single polygon that can have one or more separate boundaries. Each boundary is separated by an observation with missing values for X and Y.

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