Sample 31419: Place symbols at ZIP code locations on a U.S. map
This sample places a star at ZIP Code locations on a U.S. map.
This sample places a star at ZIP Code locations on a U.S. map.
goptions reset=all border;
/* Create a data set containing ZIP codes. */
data myzip;
input zip;
cards;
35004
85003
71601
80002
6001
19701
20001
32007
83201
60001
46001
50001
66002
40003
70001
3901
20601
1001
27513
;
run;
/* Sort the data set by ZIP codes. */
proc sort data=myzip;
by zip;
run;
/* Create a data set containing the */
/* X and Y values for my ZIP codes. */
data longlat;
/* In case there are duplicate ZIP codes, rename
X and Y from the SASHELP.ZIPCODE data set. */
merge myzip(in=mine)
sashelp.zipcode(rename=(x=long y=lat)keep=x y zip);
by zip;
/* Keep if the ZIP code was in my data set. */
if mine;
/* Convert longitude, latitude in degrees to radians */
/* to match the values in the map data set. */
x=atan(1)/45*long;
y=atan(1)/45*lat;
/* Adjust the hemisphere */
x=-x;
/* Keep only the ZIP, X and Y variables */
keep zip x y;
run;
/* Create an annotate data set to place a symbol at the
ZIP code locations. */
data anno;
/* Use the X and Y values from the LONGLAT data set. */
set longlat;
/* Set the data value coordinate system. */
/* Set the function to label. */
/* Set the size of the symbol to .75. */
/* Set a FLAG variable to signal annotate observations. */
retain xsys ysys '2' function 'label' size .75 flag 1 when 'a';
/* Set the font to the Special font. */
style='special';
/* The symbol is a star. */
text='M';
/* Specify the color for the symbol. */
color='red';
/* Output the observation to place the symbol. */
output;
run;
/* Combine the map data set with the annotate data set. */
data all;
/* Subset out the states that you do not want. */
/* The FIPS code of 2 is Alaska, 15 is Hawaii, */
/* and 72 is Puerto Rico. */
set maps.states(where=(state not in(2 15 72))) anno;
run;
/* Project the combined data set. */
proc gproject data=all out=allp;
id state;
run;
quit;
/* Separate the projected data set into a map and an annotate data set. */
data map dot;
set allp;
/* If the FLAG variable has a value of 1, it is an annotate */
/* observation; otherwise, it is a map data set observation. */
if flag=1 then output dot;
else output map;
run;
/* Define the pattern for the map. */
pattern1 v=me c=black r=50;
/* Define the title for the map. */
title 'ZIP Code locations on a US Map';
/* Generate the map and place the symbols at ZIP code locations. */
proc gmap data=map map=map;
id state;
choro state / anno=dot nolegend;
run;
quit;
This sample uses the Annotate facility to place symbols at ZIP code locations on a map. The SASHELP.ZIPCODE data set containing the ZIP code coordinates can be downloaded from the
Maps Online web site.
| Type: | Sample |
| Topic: | SAS Reference ==> Procedures ==> GMAP Query and Reporting ==> Creating Reports ==> Graphical ==> Graph Types ==> Maps ==> Special Maps
|
| Date Modified: | 2008-03-18 11:15:39 |
| Date Created: | 2008-03-10 15:04:54 |
Operating System and Release Information
| SAS System | SAS/GRAPH | Solaris for x64 | | |
| Linux for x64 | | |
| Linux on Itanium | | |
| OpenVMS Alpha | | |
| OpenVMS on HP Integrity | | |
| Solaris | | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | | |
| OpenVMS VAX | | |
| z/OS | | |
| Tru64 UNIX | | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | | |
| Microsoft Windows Server 2003 Enterprise Edition | | |
| Microsoft Windows Server 2003 Datacenter Edition | | |
| Microsoft Windows NT Workstation | | |
| Microsoft Windows 2000 Professional | | |
| Microsoft Windows 2000 Server | | |
| Microsoft Windows 2000 Datacenter Server | | |
| Microsoft Windows 2000 Advanced Server | | |
| Microsoft Windows 95/98 | | |
| OS/2 | | |
| Microsoft® Windows® for x64 | | |
| Microsoft Windows XP 64-bit Edition | | |
| Microsoft Windows Server 2003 Standard Edition | | |
| Microsoft Windows XP Professional | | |
| Windows Millennium Edition (Me) | | |
| Windows Vista | | |
| 64-bit Enabled AIX | | |
| 64-bit Enabled HP-UX | | |
| 64-bit Enabled Solaris | | |
| Linux | | |
| ABI+ for Intel Architecture | | |
| AIX | | |
| HP-UX | | |
| HP-UX IPF | | |
| IRIX | | |