Sample 44428: Create a map of the United States and Mexico
The sample code on the
Full Code tab uses the SAS® 9.3 map data sets MAPS.STATES and MAPS.MEXICO to create a combined map of the U.S. and Mexico.
Since the map data comes from different map data sets, the boundaries between the U.S. and Mexico might not align exactly. In this case, the annotation around the U.S. and Mexico covers any border discrepencies that might exist.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
The sample code below uses the SAS® 9.3 map data sets MAPS.STATES and MAPS.MEXICO to create a combined map of the U.S. and Mexico.
Since the map data comes from different map data sets, the boundaries between the U.S. and Mexico might not align exactly. In this case, the annotation around the U.S. and Mexico covers any border discrepencies that might exist.
/* Set the graphics environment */
goptions reset=all border cback=white htitle=12pt htext=10pt;
/* Create a response data set for the U.S. map */
data sampleus;
input state value;
datalines;
37 100
51 200
12 300
6 400
56 500
;
run;
/* Create a response data set for the Mexico map */
data samplemx;
input id value;
datalines;
1 100
5 200
12 300
21 400
32 500
;
run;
/* Combine the two response data sets */
data sample;
set sampleus samplemx;
run;
/* Create a map data set for the U.S. */
data states;
set maps.states(where=(state not in(2 15 72)));
run;
/* Create a map data set for Mexico */
data mexico(rename=(long=x lat=y));
set maps.mexico(drop=x y);
run;
/* Combine the two map data sets */
data mexus;
set states mexico;
run;
/* Project the map data */
proc gproject data=mexus out=mexico_us;
id id state;
run;
quit;
/* Define a variable to distinguish between the two countries */
data outlines;
set mexico_us;
if state ne . then region=1;
else region=2;
run;
/* Remove the internal boundaries */
proc gremove data=outlines out=mxus;
id id state;
by region;
run;
/* Determine the coordinates for the country borders */
data mxus;
set mxus;
by region segment;
retain flag 0;
drop flag;
if first.segment then flag=0;
if x=. then flag=1;
if flag then delete;
run;
/* Create an annotate data set to draw the country borders */
data anno_mexico_us;
retain xsys ysys '2' when 'a' color 'black' style 'mempty' size 2;
length function $8;
set mxus;
by region segment;
if first.region or first.segment then function='poly';
else function='polycont';
run;
/* Generate the graph */
title 'Map of U.S. and Mexico';
proc gmap data=sample map=mexico_us all;
id id state;
choro value / discrete coutline=graybb anno=anno_mexico_us;
run;
quit;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample uses the SAS® 9.3 map data sets MAPS.STATES and MAPS.MEXICO to create a combined map with annotated outlines for the United States and Mexico.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> GMAP Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Elements ==> Annotation
|
Date Modified: | 2012-02-08 14:51:35 |
Date Created: | 2011-09-27 15:38:48 |
Operating System and Release Information
SAS System | SAS/GRAPH | z/OS | 9.3 TS1M0 | |
Microsoft® Windows® for x64 | 9.3 TS1M0 | |
Microsoft Windows Server 2003 Datacenter Edition | 9.3 TS1M0 | |
Microsoft Windows Server 2003 Enterprise Edition | 9.3 TS1M0 | |
Microsoft Windows Server 2003 Standard Edition | 9.3 TS1M0 | |
Microsoft Windows Server 2003 for x64 | 9.3 TS1M0 | |
Microsoft Windows Server 2008 | 9.3 TS1M0 | |
Microsoft Windows Server 2008 for x64 | 9.3 TS1M0 | |
Microsoft Windows XP Professional | 9.3 TS1M0 | |
Windows 7 Enterprise 32 bit | 9.3 TS1M0 | |
Windows 7 Enterprise x64 | 9.3 TS1M0 | |
Windows 7 Home Premium 32 bit | 9.3 TS1M0 | |
Windows 7 Home Premium x64 | 9.3 TS1M0 | |
Windows 7 Professional 32 bit | 9.3 TS1M0 | |
Windows 7 Professional x64 | 9.3 TS1M0 | |
Windows 7 Ultimate 32 bit | 9.3 TS1M0 | |
Windows 7 Ultimate x64 | 9.3 TS1M0 | |
Windows Vista | 9.3 TS1M0 | |
Windows Vista for x64 | 9.3 TS1M0 | |
64-bit Enabled AIX | 9.3 TS1M0 | |
64-bit Enabled HP-UX | 9.3 TS1M0 | |
64-bit Enabled Solaris | 9.3 TS1M0 | |
HP-UX IPF | 9.3 TS1M0 | |
Linux | 9.3 TS1M0 | |
Linux for x64 | 9.3 TS1M0 | |
Solaris for x64 | 9.3 TS1M0 | |