Sample 53367: Create a map with the SGPLOT procedure
The sample code on the Full Code tab uses the SAS® 9.4 POLYGON statement in PROC SGPLOT to create a map using the SAS/GRAPH® MAPSGFK.US map data set. SAS/GRAPH software is required to run this sample.
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.4 POLYGON statement in PROC SGPLOT to create a map using the SAS/GRAPH MAPSGFK.US map data set. SAS/GRAPH software is required to run this sample.
/* Create a data set of the boundaries for the states */
data us;
set mapsgfk.us;
/* Remove Washington DC */
where id ne 'US-11';
run;
/* Create a response data set to represent in the map areas */
data response;
length state 5;
input state count;
datalines;
37 100
45 200
6 300
8 400
48 600
30 500
17 300
run;
proc sort data=response;
by state;
run;
/* Combine the response data with the map data */
data all;
merge us response;
by state;
/* Combine ID and Segment to make a unique ID */
id = catx('-', id, segment);
run;
/* Define a format for the response data */
proc format;
value mapfmt
.='No Data'
low-100='100 and under'
101-200='Between 100 and 200'
201-300='Between 200 and 300'
301-400='Between 300 and 400'
401-high='Over 400';
run;
/* Define an attribute map for the response data */
data attrmap;
id = 'maparea';
textcolor='black';
input value $20. @22 fillcolor $;
datalines;
No Data beige
100 and under cx74c476
Between 100 and 200 cx006d2c
Between 200 and 300 cx756bb1
Between 300 and 400 cx41b6c4
Over 400 cx253494
;
run;
/* Make the SAS/GRAPH annotate macros available */
%annomac;
/* Calculate the center of each polgyon
to be used to place a label */
%centroid(us,centers,id);
/* Define a label to be placed at the center of each polygon */
data all;
set all centers(rename=(x=xcen y=ycen) in=a);
/* Define the variable to contain the label for each polygon */
if a then label=fipstate(substr(id,4,2));
/* Adjust a few label coordinates */
if label = 'ID' then ycen + -.025;
if label = 'MI' then ycen + -.025;
if label = 'HI' then ycen + -.01;
if label = 'NH' then ycen + -.012;
if label = 'VT' then ycen + .01;
if label = 'MD' then ycen + .007;
if label = 'AK' then ycen + .01;
if label = 'DE' then do;
ycen + -.005;
xcen + .005;
end;
run;
/* The IMAGEMAP option enables you to view the data tips for the graph */
ods graphics / reset width=600px height=400px imagefmt=png imagename='Map' imagemap=on tipmax=4000;
title 'Counts by State';
proc sgplot data=all dattrmap=attrmap ;
format count mapfmt.;
/* Draw each polygon */
polygon x=x y=y id=id / group=count attrid=maparea
outline lineattrs=(color=gray99)
fill fillattrs=(transparency=0.5)
dataSkin=matte name='poly'
/* Remove the TIP= option to prevent data tips */
tip=(statecode count);
/* Label each polygon with the LABEL variable value */
scatter x=xcen y=ycen / markerchar=label
/* Remove the TIP= option to prevent data tips */
tip=(id);
keylegend 'poly' / title='Count Value: ';
xaxis offsetmin=0.01 offsetmax=0 display=none;
yaxis offsetmin=0.01 offsetmax=0 display=none;
run;
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.4 POLYGON statement in PROC SGPLOT to create a map using the SAS/GRAPH
® MAPSGFK.US map data set. SAS/GRAPH software is required to run this sample.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> SGPLOT
|
Date Modified: | 2014-07-10 16:28:38 |
Date Created: | 2014-07-01 09:08:28 |
Operating System and Release Information
SAS System | Base SAS | z/OS | 9.4 TS1M0 | |
Z64 | 9.4 TS1M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.4 TS1M0 | |
Microsoft® Windows® for x64 | 9.4 TS1M0 | |
Microsoft Windows 8 Enterprise x64 | 9.4 TS1M0 | |
Microsoft Windows 8 Pro x64 | 9.4 TS1M0 | |
Microsoft Windows 8.1 Enterprise 32-bit | 9.4 TS1M0 | |
Microsoft Windows 8.1 Enterprise x64 | 9.4 TS1M0 | |
Microsoft Windows 8.1 Pro | 9.4 TS1M0 | |
Microsoft Windows 8.1 Pro 32-bit | 9.4 TS1M0 | |
Microsoft Windows Server 2008 R2 | 9.4 TS1M0 | |
Microsoft Windows Server 2008 for x64 | 9.4 TS1M0 | |
Microsoft Windows Server 2012 Datacenter | 9.4 TS1M0 | |
Microsoft Windows Server 2012 R2 Datacenter | 9.4 TS1M0 | |
Microsoft Windows Server 2012 R2 Std | 9.4 TS1M0 | |
Microsoft Windows Server 2012 Std | 9.4 TS1M0 | |
Windows 7 Enterprise x64 | 9.4 TS1M0 | |
Windows 7 Professional x64 | 9.4 TS1M0 | |
64-bit Enabled AIX | 9.4 TS1M0 | |
64-bit Enabled HP-UX | 9.4 TS1M0 | |
64-bit Enabled Solaris | 9.4 TS1M0 | |
HP-UX IPF | 9.4 TS1M0 | |
Linux for x64 | 9.4 TS1M0 | |
Solaris for x64 | 9.4 TS1M0 | |