Examples


The following examples include features from one or more of the GMAP statements.

Example 1: Producing a Simple Block Map

Procedure features:

  • ID statement

  • BLOCK statement option:

    • CBLKOUT=

Sample library member: GMPSIMPL

click to expand

This example produces a block map that shows the total number of hazardous waste sites in each state in 1997. Since the DISCRETE option is not used, the response variable is assumed to have a continuous range of values. Because neither the LEVELS= nor MIDPOINTS= option is used, the GMAP procedure selects a number of levels based on the number of map areas and then calculates the appropriate response levels.

The blocks use the default pattern, which is a solid fill that rotates through the colors list. Because the colors list is specified in the GOPTIONS statement, all colors are used in the rotation. CBLKOUT= outlines the blocks in black, instead of using the default outline color, which is the first color in the list “ in this case, BLUE.

The map areas use the default pattern for map areas in a block map. This is the first hatch pattern for maps, M2N0. By default, both the fill and the outline use the first color in the colors list.

Assign the libref and set the graphics environment. COLORS= specifies the colors list, which is used by the default patterns and outlines. CTEXT= specifies the color for all text on the output.

 libname maps '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(blue green lime lipk cyan red)           ctext=black ftext=swiss htitle=6 htext=3; 

Create response data set SITES. This data set contains a map area identification variable, STATE, and a response variable, SITES. The STFIPS function is used to convert the state postal codes to FIPS state codes. STATE contains the FIPS codes for each state and matches the values of STATE in the MAPS.US data set. SITES contains the total number of waste sites installed in the state.

 data sites;     length stcode $ 2;     input region stcode $ sites;     state=stfips(stcode);     datalines;  6   AR  12  10  AK  7    moredata lines    3   WV  6  8   WY  3  ; 

Define title and footnote for map.

 title1 'Hazardous Waste Site Installations (1997)';  footnote1 j=r 'GMPSIMPL'; 

Produce the block map. The ID statement specifies the variable that is in both the map data set and the response data set and defines map areas. The BLOCK statement specifies the variable in the response data set that contains the response values for each of the map areas. CBLKOUT= specifies the color for the block outlines.

 proc gmap map=maps.us data=sites;     id state;     block sites / cblkout=black;  run;  quit; 

Example 2: Specifying Response Levels in a Block Map

Procedure features:

  • BLOCK statement options:

    • LEGEND=

    • LEVELS=

    • SHAPE=

    • XVIEW =

    • ZVIEW=

Other features:

  • LEGEND statement

  • PATTERN statement

Sample library member: GMPLEVEL

click to expand

This example uses LEVELS= to specify the number of response levels for the blocks. LEVELS= tells GMAP how many response levels and GMAP calculates the quantiles. Eight PATTERN statements explicitly define a color for each of these response levels.

A single PATTERN statement uses the REPEAT= option to define an empty map/plot pattern outlined in black for all the map areas.

The example also changes the viewpoint by rotating the map to provide a better view of the northeast states. As a result, the blocks appear shorter.

Assign the libref and set the graphics environment.

 libname maps '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(black blue green red)           ctext=black ftext=swiss htitle=6 htext=3; 

Create response data set SITES. This data set contains a map area identification variable, STATE, and a response variable, SITES. The STFIPS function is used to convert the state postal codes to FIPS state codes. STATE contains the FIPS codes for each state and matches the values of STATE in the MAPS.US data set. SITES contains the total number of waste sites installed in the state.

 data sites;     length stcode $ 2;     input region stcode $ sites;     state=stfips(stcode);     datalines;  6   AR  12  10  AK  7    moredata lines    3   WV  6  8   WY  3  ; 

Define title and footnote for map.

 title1 'Hazardous Waste Site Installations (1997)';  footnote1 j=r 'GMPLEVEL'; 

Define the patterns for the blocks. PATTERN statements 1-8 specify bar/block patterns and cannot be used by the map areas. They are applied to the blocks in order of the response level.

 pattern1 value=solid color=lime;  pattern2 value=solid color=cyan;  pattern3 value=solid color=green;  pattern4 value=solid color=blue;  pattern5 value=solid color=lipk;  pattern6 value=solid color=red;  pattern7 value=solid color=gray;  pattern8 value=solid color=black; 

Define a pattern for the map areas. PATTERN9 defines a single map pattern that is repeated for each of the 50 map areas (states). The pattern is an empty fill with a black border. VALUE= defines a map/plot pattern, which cannot be used by the blocks. Specifying a color causes PATTERN9 to generate only one pattern definition. REPEAT= specifies the number of times to repeat the pattern definition.

 pattern9 value=empty color=black repeat=50; 

Define legend characteristics. LABEL= produces a two line label and places it to the left of the legend values. FRAME draws a border around the legend using the first color in the colors list.

 legend1 value=(justify=left)          label=('Number' justify=left 'of Sites:'                 position=(middle left))          frame; 

Produce the block map. LEVELS= specifies the number of response levels for the graph. SHAPE= draws the blocks as 3D cylinders . XVIEW= changes the viewpoint for the map so that the map appears to be slightly rotated . ZVIEW= raises the height of the viewpoint. LEGEND= assigns the LEGEND1 statement to the map legend.

 proc gmap map=maps.us data=sites;     id state;     block sites / levels=8                   shape=cylinder                   xview=0.75                   zview=5                   legend=legend1;  run;  quit; 

Example 3: Assigning a Format to the Response Variable

Procedure features:

  • BLOCK statement options:

    • AREA=

    • CBLKOUT=

    • COUTLINE=

    • DISCRETE

    • WOUTLINE=

Other features:

  • FORMAT statement

  • LEGEND statement

  • PATTERN statement

Sample library member: GMPFORMT

click to expand

This example creates a format that defines the ranges of values for the response values and assigns this format to the response variable. These ranges appear in the legend and make the map easier to understand. When a format is assigned to a numeric response variable, the DISCRETE option must be used so that each formatted value is treated as a separate response level.

The example also patterns the map areas by region. To do this, both data sets must contain the ID variable, REGION. The response data set, SITES, already contains REGION, so the program only needs to add it to the map data set. Then the map data set is sorted by both the ID variables , REGION and STATE. Finally, the AREA= option specifies that the ID variable REGION is the one by which the map areas are patterned .

Assign the libref and set the graphics environment.

 libname maps '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(black blue green red)           ftext=swiss htitle=6 htext=3; 

Create map data set STATES1 by adding REGION to the MAPS.US map data set.

 data states1;     set maps.us;     select;        when (state in (9,23,25,33,44,50))       region=1;        when (state in (34,36))                  region=2;        when (state in (10,11,24,42,51,54))      region=3;        when (state in (1,12,13,21,28,37,45,47)) region=4;        when (state in (17,18,26,27,39,55))      region=5;        when (state in (5,22,35,40,48))          region=6;        when (state in (19,20,29,31))            region=7;        when (state in (8,30,38,46,49,56))       region=8;        when (state in (4,6,15,32))              region=9;        otherwise                                region=10;     end;  run; 

Sort the new map data set. The map data must be sorted in the order of the ID variables.

 proc sort data=states1 out=states2;     by region state;  run; 

Create response data set SITES. This data set contains a map area identification variable, STATE, and a response variable, SITES. The STFIPS function is used to convert the state postal codes to FIPS state codes. STATE contains the FIPS codes for each state and matches the values of STATE in the MAPS.US data set. SITES contains the total number of waste sites installed in the state.

 data sites;     length stcode $ 2;     input region stcode $ sites;     state=stfips(stcode);     datalines;  6   AR  12  10  AK  7    moredata lines    3   WV  6  8   WY  3  ; 

Create a format for SITES. SITESFMT. defines and labels the ranges of values for SITES.

 proc format;     value sitesfmt low-24='0-24'                    25-49='25-49'                    50-74='50-74'                    75-99='75-99'                    100-high='over 100';  run; 

Define title and footnote for map.

 title1 'Hazardous Waste Site Installations (1997)';  footnote j=r 'GMPFORMT'; 

Define a hatch pattern for the map areas. PATTERN1 defines a dense hatch pattern for the map areas. Because there are four colors in the colors list, the pattern rotation must be repeated three times to create enough patterns for the ten regions .

 pattern1 value=m3n0 r=3; 

Define a solid pattern for the blocks. PATTERN2 through PATTERN6 define the patterns for the block surfaces.

 pattern2 value=solid color=green;  pattern3 value=solid color=cyan;  pattern4 value=solid color=lime;  pattern5 value=solid color=blue;  pattern6 value=solid color=red; 

Define legend characteristics.

 legend1 shape=bar(2,4)          value=(j=l)          label=('Number' j=l 'of Sites:')          frame; 

Produce the block maps. The FORMAT statement assigns SITESFMT. to the response variable. DISCRETE specifies that each formatted value is a separate response level. AREA= specifies that the map surface should be patterned by the first variable in the ID statement, REGION. CBLKOUT= and COUTLINE= specify the color that outlines the blocks and the regions, respectively. WOUTLINE= specifies the width of the block outline in pixels.

 proc gmap map=states2 data=sites;     format sites sitesfmt.;     id region state;     block sites / discrete                   area=1                   legend=legend1                   shape=block                   cblkout=black                   coutline=black                   woutline=3;  run;  quit; 

Example 4: Producing a Simple Choropleth Map

Procedure features:

  • ID statement

  • CHORO statement option:

    • COUTLINE=

Sample library member: GMPCHORO

click to expand

This example produces a choropleth (2D) map that shows the total number of hazardous waste sites in each state in 1997. Since the DISCRETE option is not used, the response variable is assumed to have a continuous range of values. Because neither the LEVELS= nor MIDPOINTS= option is used, the GMAP procedure selects a number of levels based on the number of map areas and then calculates the appropriate response levels. The legend shows the midpoint value of each level.

The map areas use the default pattern, which is a solid fill that rotates through the colors list. Because the colors list is specified in the GOPTIONS statement, all colors are used in the rotation. COUTLINE= outlines the map areas in gray, instead of the default outline color, which is the first color in the list, in this case, BLUE.

Assign the libref and set the graphics environment. COLORS= specifies the colors list, which is used by the default patterns and outlines. CTEXT= specifies the color for all text on the output.

 libname maps '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(blue green lime lipk cyan red)           ctext=black ftext=swiss htitle=6 htext=3; 

Create response data set SITES. This data set contains a map area identification variable, STATE, and a response variable, SITES. The STFIPS function is used to convert the state postal codes to FIPS state codes. STATE contains the FIPS codes for each state and matches the values of STATE in the MAPS.US data set. SITES contains the total number of waste sites installed in the state.

 data sites;     length stcode $ 2;     input region stcode $ sites;     state=stfips(stcode);     datalines;  6   AR  12  10  AK  7    moredata lines    3   WV  6  8   WY  3  ; 

Define title and footnote for map.

 title1 'Hazardous Waste Site Installations (1997)';  footnote1 j=r 'GMPCHORO'; 

Produce the choropleth map. The ID statement specifies the variable that is in both the map data set and the response data set that defines map areas. COUTLINE= specifies the color for the map area outlines.

 proc gmap map=maps.us data=sites;     id state;    choro sites / coutline=gray;  run;  quit; 

Example 5: Creating Maps with Drill-down for the Web

Procedure Features:

  • CHORO statement options:

    • DES=

    • DISCRETE

    • HTML=

    • NAME =

  • BLOCK statement options:

    • BLOCKSIZE=

    • DES=

    • MIDPOINTS=

    • NAME=

ODS Features:

  • ODS HTML statement :

    • BODY=

    • CONTENTS=

    • FRAME=

    • NOGTITLE

    • PATH =

Other Features:

  • BY statement

  • GOPTIONS statement

  • LEGEND statement

  • PATTERN statement

  • TITLE statement

Sample library member: GMPDRILL

This example shows how to create a 2D choropleth map with simple drill-down functionality for the Web. When this map is displayed in a browser, you can select an area of the map and display additional information about the data.

The example explains how to use the ODS HTML statement and the HTML procedure options to create the drill-down. It shows how to

  • explicitly name the HTML files and open and close them throughout the program

  • use BY- group processing with ODS HTML, including storing multiple graphs in one file and incrementing anchor names, catalog entry names, and graphics file names

  • use the PATH= option to specify the destination for the HTML and GIF files created by the ODS HTML statement

  • use the NAME= option to name the graphics catalog entries

  • assign anchor names to the graphics output with the ANCHOR= option in the ODS HTML statement

  • add an HTML HREF string to a data set to define a link target

  • assign link targets with the HTML= procedure option

  • use DES= to control the text of the table of contents entry

  • suppress the titles in the GIF files and display them in the HTML file.

For more information, see ODS HTML Statement on page 164.

The example also illustrates other CHORO and BLOCK statement options.

The program produces one choro map that shows Environmental Protection Agency (EPA) regions and block maps of the states in each region. Each block map shows the number of hazardous waste sites for each state in the selected region. Figure 35.10 on page 1055 shows the map of the EPA regions.

click to expand
Figure 35.10: Browser View of Regional Map

Figure 35.11 on page 1056 shows the block map that appears when you select Region 5 in the map.

click to expand
Figure 35.11: Browser View of Region 5 Block Map

Assign the libref and the Web-server path. FILENAME assigns the fileref ODSOUT, which specifies a destination for the HTML and GIF files produced by the example program. To assign that location as the HTML destination for program output, ODSOUT is specified later in the program on the ODS HTML statement s PATH= option. ODSOUT must point to a Web-server location if procedure output is to be viewed on the Web.

 libname maps '  SAS-MAPS-library  ';  filename odsout '  path-to-Web-server-space  '; 

Close the ODS Listing destination for procedure output, and set the graphics environment. To conserve system resources, ODS LISTING CLOSE closes the Listing destination for procedure output. Thus, the graphics output is not displayed in the GRAPH window, although it is written to the catalog.

 ods listing close;  goptions reset=global gunit=pct cback=white           colors=(black blue green red)           ftext=swiss htitle=6 htext=3.5; 

Create the data set SITES. SITES contains the FIPS codes for each state and the total number of hazardous waste sites installed in each state. The STFIPS function converts state postal codes to FIPS state codes.

 data sites;     length stcode $ 2;     input region stcode $ sites;     state=stfips(stcode);     datalines;  1   AK  12  4   AL  7  4   AR  12  2   AZ  10  1   CA  90  1   CO  15  5   CT  15  5   DE  18  4   FL  52  4   GA  15  1   HI  4  3   IA  16  1   ID  8  3   IL  38  3   IN  30  3   KS  10  4   KY  16  4   LA  15  5   MA  30  4   MD  13  5   ME  12  3   MI  72  3   MN  30  3   MO  22  4   MS  1  1   MT  8  4   NC  22  3   ND  0  3   NE  10  5   NH  18  5   NJ  105  2   NM  9  1   NV  1  5   NY  78  3   OH  34  2   OK  10  1   OR  10  5   PA  100  5   RI  12  4   SC  26  3   SD  2  4   TN  14  2   TX  26  1   UT  12  4   VA  25  5   VT  8  1   WA  49  3   WI  40  5   WV  6  1   WY  3  ; 

Add the HTML variable to SITES and create the NEWSITES data set. The HTML variable REGIONDRILL contains the targets for the values of the variable REGION.

 data newsites;     length regiondrill ;     set sites;     if region=1 then        regiondrill='HREF="hazsite_statebody.html#Region1"';     if region=2 then        regiondrill='HREF="hazsite_statebody.html#Region2"';     if region=3 then        regiondrill='HREF="hazsite_statebody.html#Region3"';     if region=4 then        regiondrill='HREF="hazsite_statebody.html#Region4"';     if region=5 then        regiondrill='HREF="hazsite_statebody.html#Region5"';  run; 

Assign graphics options for producing the ODS HTML output . DEVICE=GIF causes the ODS HTML statement to generate the graphics output as GIF files. TRANSPARENCY causes the graphics output to use the Web-page background as the background of the graph.

 goptions device=gif transparency; 

Open the ODS HTML destination. BODY= names the file for storing HTML output. CONTENTS= names the HTML file that contains the table of contents to the HTML procedure output. The contents file links to each of the body files written to the HTML destination. FRAME= names the HTML file that integrates the contents and body files. NOGTITLE suppress the graph titles from the SAS/GRAPH output and displays them through the HTML page. PATH= specifies the ODSOUT fileref as the HTML destination for all the HTML and GIF files.

 ods html body='hazsite_mapbody.html'           contents='hazsite_contents.html'           frame='hazsite_frame.html'           nogtitle           path=odsout; 

Define the title and footnote for the map of the EPA regions.

 title1 'Hazardous Waste Sites in EPA Regions (1997)';  footnote1 h=3 j=l 'click on a map region' j=r 'GMPDRIL1'; 

Define a map pattern for each region. Each PATTERN statement defines one map/plot pattern. The patterns are assigned to the map areas that represent the EPA regions

 pattern1 value=msolid color=blue;  pattern2 value=msolid color=green;  pattern3 value=msolid color=red;  pattern4 value=msolid color=lime;  pattern5 value=msolid color=cyan; 

Generate the regional map. The ID statement specifies the variable that defines the map areas and is in both the map data set and the response data set. DISCRETE specifies that each value of the numeric response variable, STATE, be treated as a separate response level. HTML= specifies REGIONDRILL as the variable that contains the targets for the map regions. Specifying HTML variables causes SAS/GRAPH to add an image map to the HTML body file. DES= specifies the description that is stored in the catalog and used in the Table of Contents. NAME= specifies the name of the graphics catalog entry. Because the PATH= destination is a file storage location and not a specific file name, the catalog entry name EPAMAP is automatically assigned to the GIF file.

 proc gmap map=maps.us data=newsites;     id state;     choro region / discrete                    html=regiondrill                    coutline=black                    nolegend                    des='EPA Regional Map'                    name='epamap';  run;  quit; 

Open a new body file for the state maps. Assigning a new body file closes HAZSITE_MAPBODY.HTML. The contents and frame files, which remain open, will provide links to all body files. ANCHOR= specifies the name of the anchor that identifies the link target. This name is automatically incremented when the graphics output is generated. GTITLE uses titles in the GIF files.

 ods html body='hazsite_statebody.html'           anchor='Region1'           gtitle           path=odsout; 

Assign new graphics options for ODS HTML output. The active device is still GIF.

 goptions notransparency           border; 

Sort the response data set NEWSITES in order of the BY variable. The data must be in sorted order before running the GMAP procedure with BY-group processing.

 proc sort data=newsites;     by region;  run; 

Define legend characteristics for the state maps. VALUE= specifies text for the legend values that describes the ranges specified by MIDPOINTS= in the BLOCK statement.

 legend1 shape=bar(3,4)          label=('Number of Sites'                 position=(top center))          value=(j=l '0-24' '25-49' '50-74' '75-99' 'over 100')          frame; 

Define a pattern for the map areas. Because the procedure uses BY-group processing to generate the maps, all map areas use the same map pattern.

 pattern1 value=ms color=gray; 

Define the patterns for the blocks.

 pattern2 value=solid color=lipk;  pattern3 value=solid color=cyan;  pattern4 value=solid color=green;  pattern5 value=solid color=blue;  pattern6 value=solid color=red; 

Suppress the default BY-line and define a title that includes the BY-values. # BYVAL inserts the value of the BY variable into the title of each block map.

 options nobyline;  title1 'Wastes Sites per State in Region #byval(region)';  footnote1 h=3 j=r 'GMPDRIL2'; 

Generate the block maps for each region. MIDPOINTS= defines the midpoints of the ranges described in the legend. NAME= is a full 8 characters ending in 1 so the incremented names match the regions. NAME= specifies the name of the first catalog entry. Because BY-group processing generates multiple graphs from one BLOCK statement, the name assigned by NAME= is incremented to provide a unique name for each piece of output. These names are automatically assigned to the GIF files. DES= specifies the description that is stored in the catalog and used in the Table of Contents. Because BY-group processing is used, the same description is assigned to all the output.

 proc gmap map=maps.us data=newsites;     by region;     id state;     block sites / midpoints=(12 37 62 87 112)                   legend=legend1                   shape=cylinder                   blocksize=4                   coutline=black                   des='State Maps'                   name='states01';  run;  quit; 

Close the ODS HTML destination, and open the ODS Listing destination. You must close the HTML destination before you can view the output with a browser.

 ods html close;  ods listing; 

Example 6: Labeling the States on a U.S. Map

Procedure features:

  • CHORO statement options:

    • ANNOTATE=

    • NOLEGEND

Other features:

  • Annotate Facility

Sample library member: GMPLABEL

click to expand

This example uses the MAPS.USCENTER data set and the Annotate facility to add postal code labels to each state. The program first builds an Annotate data set that contains the instructions for drawing the labels. Some of the labels are in the center of the state and others use external labeling with leader lines. The CHORO statement assigns the Annotate data set to the map.

Note: The coordinates in MAPS.USCENTER have been projected to match coordinates in the MAPS.US data set.

Assign the libref and set the graphics environment.

 libname maps '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(black blue green red)           ftext=swiss htitle=6 htext=3; 

Create annotate data set, CENTER, from MAPS.USCENTER. The annotate data set 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). The FIPSTATE function converts the FIPS codes to state postal codes.

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

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

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

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.

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

When external labeling is in effect, Annotate draws the leader line and resets the flag.

 else if flag=1 then        do;           function='draw';           size=.25;           flag=0;        end;     output;  run; 

Define title and footnote for map.

 title 'Positioning State Labels with MAPS.USCENTER';  footnote j=r 'GMPLABEL'; 

Define pattern characteristics. PATTERN1 defines a single map pattern that is repeated for each of the 50 map areas (states). The pattern is an empty fill with a blue border. VALUE= defines a map/plot pattern, which cannot be used by the blocks. Specifying a color causes PATTERN1 to generate only one pattern definition. REPEAT= specifies the number of times to repeat the pattern definition.

 pattern1 value=mempty color=blue repeat=50; 

Produce the choropleth map. NOLEGEND suppresses the legend. ANNOTATE= specifies the data set to annotate the map.

 proc gmap data=maps.us map=maps.us;     id state;     choro state / nolegend                   annotate=center;  run;  quit; 

Example 7: Producing a Simple Prism Map

Procedure features:

  • ID statement

  • PRISM statement option:

    • COUTLINE=

Sample library member: GMPPRISM

click to expand

This example produces a prism map of the hazardous waste sites. Since the DISCRETE option is not used, the response variable is assumed to have a continuous range of values. Because neither the LEVELS= nor MIDPOINTS= option is used, the GMAP procedure selects a number of levels based on the number of map areas and then calculates the appropriate response levels.

The map areas use the default pattern, which is a solid fill that rotates through the colors list. Because the colors list is specified in the GOPTIONS statement, all colors are used in the rotation. COUTLINE= outlines the map areas in gray, instead of the default outline color, which is the first color in the list, in this case, BLUE.

Since the XVIEW=, YVIEW=, and ZVIEW= options are not used, the default viewing position, above and to the east and south of the center of the map, is used. Since the XLIGHT= and YLIGHT= options are not used, none of the side polygons of the prisms are shadowed . The light source is the same as the viewing position.

Assign the libref and set the graphics environment. COLORS= specifies the colors list, which is used by the default patterns and outlines. CTEXT= specifies the color for all text.

 libname maps '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(blue green lime lipk cyan red)           ctext=black ftext=swiss htitle=6 htext=3; 

Create response data set SITES. This data set contains a map area identification variable, STATE, and a response variable, SITES. The STFIPS function is used to convert the state postal codes to FIPS state codes. STATE contains the FIPS codes for each state and matches the values of STATE in the MAPS.US data set. SITES contains the total number of waste sites installed in the state.

 data sites;     length stcode $ 2;     input region stcode $ sites;     state=stfips(stcode);     datalines;  6   AR  12  10  AK  7    moredata lines    3   WV  6  8   WY  3  ; 

Define title and footnote for the map.

 title1 'Hazardous Waste Site Installations (1997)';  footnote1 j=r 'GMPPRISM'; 

Produce the prism map. The ID statement specifies the variable in the map data set and the response data set that defines map areas. COUTLINE= specifies the map area outline color.

 proc gmap map=maps.us data=sites;     id state;     prism sites / coutline=gray;  run;  quit; 

Example 8: Specifying Midpoints in a Prism Map

Procedure features:

  • PRISM statement options:

    • LEGEND=

    • MIDPOINTS=

    • XLIGHT=

    • XVIEW=

    • ZVIEW=

Other features:

  • LEGEND statement

Sample library member: GMPMIDPT

click to expand

This example explicitly specifies the midpoints for three response levels. Each response level uses the default solid pattern and a color from the colors list.

The example also changes the map viewpoint and light source.

Assign the libref and set the graphics environment. COLORS= specifies the colors list, which is used by the default patterns and outlines. CTEXT= specifies the color for all text.

 libname maps '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(blue green red) ctext=black           ftext=swiss htitle=6 htext=3; 

Create response data set SITES. This data set contains a map area identification variable, STATE, and a response variable, SITES. The STFIPS function is used to convert the state postal codes to FIPS state codes. STATE contains the FIPS codes for each state and matches the values of STATE in the MAPS.US data set. SITES contains the total number of waste sites installed in the state.

 data sites;     length stcode $ 2;     input region stcode $ sites;     state=stfips(stcode);     datalines;  6   AR  12  10  AK  7    moredata lines    3   WV  6  8   WY  3  ; 

Define title and footnote for map.

 title1 'Hazardous Waste Site Installations (1997)';  footnote1 j=r 'GMPMIDPT'; 

Define legend characteristics. CBORDER= draws a black frame around the legend. If FRAME were specified, it would be BLUE, the first color in the colors list.

 legend shape=bar(4,4)         value=(j=l)         label=('Number of Sites:'                j=l '(midpoint of range)')         cborder=black; 

Produce the prism map. MIDPOINTS= specifies three response levels for the map. XLIGHT= moves the light source to the right and adds shadows to the left-side polygons of the prisms. XVIEW= and ZVIEW= shift the viewing point to the right and upward, respectively. This reduces the number of prisms that are partially hidden by taller neighbors.

 proc gmap map=maps.us data=sites;     id state;     prism sites / midpoints=25 50 75                   xlight=5                   xview=.75                   zview=5                   legend=legend                   coutline=gray;  run;  quit; 

Example 9: Producing a Simple Surface Map

Procedure features:

  • SURFACE statement

Sample library member: GMPSURFA

click to expand

This example produces a surface map that shows the total number of hazardous waste sites in each state in 1997. Because the CONSTANT= and NLINES= options are not used, the GMAP procedure draws a surface that consists of 50 lines and uses the default decay function to calculate spike height and base width. And because the ROTATE= and TILT= options are not used, the map is rotated 70 degrees around the Z axis and tilted 70 degrees with respect to the X axis.

Assign the libref and set the graphics environment. COLORS= specifies the colors list. By default the map uses the first color in the list.

 libname maps '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(black blue green red)           ftext=swiss htitle=6 htext=3; 

Create response data set SITES. This data set contains a map area identification variable, STATE, and a response variable, SITES. The STFIPS function is used to convert the state postal codes to FIPS state codes. STATE contains the FIPS codes for each state and matches the values of STATE in the MAPS.US data set. SITES contains the total number of waste sites installed in the state.

 data sites;     length stcode $ 2;     input region stcode $ sites;     state=stfips(stcode);     datalines;  6   AR  12  10  AK  7    moredata lines    3   WV  6  8   WY  3  ; 

Define title and footnote for the map.

 title1 'Hazardous Waste Site Installations (1997)';  footnote1 j=r 'GMPSURFA'; 

Produce the surface map. The ID statement specifies the variable in the map data set and the response data set that defines the map areas.

 proc gmap map=maps.us data=sites;     id state;     surface sites;  run;  quit; 

Example 10: Rotating and Tilting a Surface Map

Procedure features:

  • SURFACE statement options:

    • CONSTANT=

    • NLINES=

    • ROTATE=

    • TILT=

Sample library member: GMPROSUR

click to expand

This example tilts and rotates the surface map and uses more lines to draw the surface.

Assign the libref and set the graphics environment.

 libname maps '  SAS-data-library  ';  goptions reset=global gunit=pct border cback=white           colors=(black blue green red)           ftext=swiss htitle=6 htext=3; 

Create response data set SITES. This data set contains a map area identification variable, STATE, and a response variable, SITES. The STFIPS function is used to convert the state postal codes to FIPS state codes. STATE contains the FIPS codes for each state and matches the values of STATE in the MAPS.US data set. SITES contains the total number of waste sites installed in the state.

 data sites;     length stcode $ 2;     input region stcode $ sites;     state=stfips(stcode);     datalines;  6   AR  12  10  AK  7    moredata lines    3   WV  6  8   WY  3  ; 

Define title and footnote for the map.

 title1 'Hazardous Waste Site Installations (1997)';  footnote1 j=r 'GMPROSUR'; 

Produce the surface map. CONSTANT= specifies a value that is less than the default value so the spikes are narrower at the base. NLINES= specifies the maximum number of map lines, which gives the best map shape resolution. ROTATE= and TILT= adjust the map orientation to make the crowded spikes in the northeast portion of the map easier to distinguish.

 proc gmap map=maps.us data=sites;     id state;     surface sites / constant=4                     nlines=100                     rotate=40                     tilt=60;  run;  quit; 

Example 11: Creating a Map Using the Feature Table

Procedure Features:

  • ID statement

  • CHORO statement option:

    • DISCRETE

ODS Features:

  • ODS HTML statement:

    • BODY=

Other Features:

  • MERGE statement

  • GOPTIONS statement

Sample library member: GMPSPATL

When you use a feature table on PROC GMAP, you merge the feature table with your response data set before generating a map, storing the combined data in a new data set. On PROC GMAP, you use the DATA= option to name the combined data set, and you use the ID statement to identify the variable that contains the spatial information.

To illustrate the use of a feature table, assume you want to generate a map of the United States. Rather than using the traditional map data set MAPS.US, you want to use its corresponding feature table. To determine which feature table corresponds to a traditional map data set, look in the MAPS.METAMAPS data set:

  • The feature table MAPS.US2 corresponds to the traditional map data set MAPS.US.

  • In MAPS.US2, the values of the variable _MAP_GEOMETRY_ encapsulate the geometry object.

The sample program uses the following procedures and statements:

  • PROC SORT sorts the current data set, WORK.SITES, by the values of variable STATE. This prepares SITES for a merge with the feature table MAPS.US2, which is delivered with SAS/GRAPH. The variable STATE identifies the map areas in both SITES and MAPS.US2.

  • PROC SORT sorts the feature table MAPS.US2. The OUT= option specifies that the sorted data be written to a new data set WORK.MAPS.

  • In the DATA step, the MERGE statement merges the feature table with the response data. The combined data set is saved to a new data set named BOTH. The data set BOTH is stored in WORK, a temporary library. To use the combined data set in other SAS/GRAPH programs, you would need to save the merged data set to a permanent library.

  • On the PROC GMAP statement, the DATA= option points to the combined data set, BOTH. The ID statement specifies _MAP_GEOMETRY_ as the variable that contains the spatial data. Because both the map and response data are stored in a single data set, the MAP= option is not required on the PROC GMAP statement.

The following example creates the response data set SITES and merges it with the feature table US2. It then uses the combined data set to generate a map as a SAS/GRAPH Control for ActiveX.

click to expand

Specify a valid file name and assign the libref for the SAS Maps library. This program generates one HTML file. FILENAME assigns the fileref ODSOUT, which specifies a destination for the HTML file that is produced by the sample program. External-html-file needs to be replaced with the complete path specifying where the files will be located. The following two lines are the only lines that need to be changed to run the program.

 filename odsout 'external-html-file' ;  libname maps 'SAS-data-library'; 

Create the data set SITES with regional data. Sites contains a region number for each state and the total number of hazardous waste sites in each state. The STFIPS function converts the state postal codes to FIPS state codes.

 data sites;     length stcode $ 2;     input region stcode $ sites;     state=stfips(stcode);     datalines;  6   AR  12  10  AK  7  4   AL  12  9   AZ  10  9   CA  90  8   CO  15  1   CT  15  3   DE  18  4   FL  52  4   GA  15  9   HI  4  7   IA  16  10  ID  8  5   IL  38  5   IN  30  7   KS  10  4   KY  16  6   LA  15  1   MA  30  3   MD  13  1   ME  12  5   MI  72  5   MN  30  7   MO  22  4   MS  1  8   MT  8  4   NC  22  8   ND  0  7   NE  10  1   NH  18  2   NJ  105  6   NM  9  9   NV  1  2   NY  78  5   OH  34  6   OK  10  10  OR  10  3   PA  100  1   RI  12  4   SC  26  8   SD  2  4   TN  14  6   TX  26  8   UT  12  3   VA  25  1   VT  8  10  WA  49  5   WI  40  3   WV  6  8   WY  3  ; 

Sort the response and the feature tables in the order of the BY variable. By default, the first PROC SORT sorts the response data set created in the code above. Both sorted data sets are stored in the SAS temporary library WORK. To allow the data sets to be merged, the same BY variable is used to sort both the response and feature tables.

 proc sort;     by state;  run;  proc sort data=maps.us2 out=maps;     by state;  run; 

Merge the data sets.

 data both;     merge maps sites;     by state;  run; 

Specify the ACTIVEX driver and HTML output. To conserve system resources, ODS LISTING CLOSE closes the Listing destination for procedure output. In the program s ODS HTML statement, the BODY= option names the file for storing HTML output. ODSOUT is defined in the beginning of the code in the FILENAME statement.

 goptions reset=all device=activex;  ods listing close;  ods html body='odsout.html'  path=odsout; 

Define title and footnote for the map.

 title1 'Region Map Created with a Feature Table';  footnote1 j=r 'GMPSPATL'; 

Generate the choropleth map using the merged response data set and feature table. The ID variable is the $GEOREF formatted variable containing the spatial information. DISCRETE specifies that each level of REGION is a separate response level.

 proc gmap data=both;    id _map_geometry_;    choro region/discrete; run; quit; 

Close the HTML destination and open the listing destination. The HTML destination must be closed before you can view the output with a browser. ODS LISTING opens the Listing destination again so that the destination is again available for displaying output during this SAS session.

 ods html close;  ods listing; 



SAS.GRAPH 9.1 Reference, Volumes I and II
SAS.GRAPH 9.1 Reference, Volumes I and II
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 342

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net