The section begins by converting the X (longitude) and Y (latitude) variables from radians to degrees, to align them with the projection types expected by the CHOROMAP procedure. Next, plot data is created by filtering to include only the 48 continental states and collecting the FIPS (Federal Information Processing Standards) codes of the states. A global title and a footnote are assigned to contextualize the graph. Finally, the SGMAP procedure is executed, using a states map dataset, U.S. Census Bureau 2010 population response data (here simulated by scoreperstate), and the plot dataset. The ESRIMAP statement is used to create a base map, CHOROMAP to plot state populations with a color gradient, and TEXT to assign state names. A gradient legend is added with GRADLEGEND for better interpretation of average credit scores.
Data Analysis
Type : SASHELP_AND_INTERNAL_CREATION
The examples use the SASHELP.MAPS libraries (MAPS.STATES, MAPS.USCENTER) and an internal 'scoreperstate' dataset created via a DATA step for example autonomy.
1 Code Block
DATA STEP Data
Explanation : Creation of a dummy dataset 'work.scoreperstate' to simulate average credit scores by state, necessary to make the example autonomous. State FIPS codes are used as identifiers.
Explanation : This step converts the longitude (X) and latitude (Y) variables from the MAPS.STATES dataset from radians to degrees, which is necessary to align the projection types. States 2 (Alaska), 15 (Hawaii), and 72 (Puerto Rico) are excluded.
Copied!
data states;
set maps.states;
if state ^in(2,15,72); /* Exclut l'Alaska, Hawaï et Porto Rico */
x = -x * 45/atan(1); /* Conversion de la longitude en degrés */
y = y * 45/atan(1); /* Conversion de la latitude en degrés */
run;
1
DATA states;
2
SET maps.states;
3
IF state ^in(2,15,72); /* Exclut l'Alaska, Hawaï et Porto Rico */
4
x = -x * 45/atan(1); /* Conversion de la longitude en degrés */
5
y = y * 45/atan(1); /* Conversion de la latitude en degrés */
6
RUN;
3 Code Block
DATA STEP
Explanation : This DATA step creates the 'plot_data' dataset from MAPS.USCENTER, filtering the lower 48 states and converting the longitude. It also generates the state name from the FIPS code and a `state_fips` formatted for joining with score data.
Copied!
data plot_data;
set maps.uscenter;
if state ^in(2,15,72) and ocean^='Y';
long = -long;
statename = fipstate(state); /* Récupère le code FIPS de l'état */
state_fips = put(state, z2.); /* Crée une variable state_fips à partir de 'state' pour la jointure */
run;
1
DATA plot_data;
2
SET maps.uscenter;
3
IF state ^in(2,15,72) and ocean^='Y';
4
long = -long;
5
statename = fipstate(state); /* Récupère le code FIPS de l'état */
6
state_fips = put(state, z2.); /* Crée une variable state_fips à partir de 'state' pour la jointure */
7
RUN;
4 Code Block
Global Statements
Explanation : Uses global TITLE and FOOTNOTE statements to define the main graph title and an explanatory footnote.
Copied!
title 'Average Credit Score in Each State';
footnote4 'Map only includes the lower 48 states in the United States';
1
title 'Average Credit Score in Each State';
2
footnote4 'Map only includes the lower 48 states in the United States';
3
5 Code Block
PROC SGMAP
Explanation : Executes the SGMAP procedure to generate the graph. It uses the 'states', 'scoreperstate', and 'plot_data' datasets. ESRIMAP defines the base map, CHOROMAP plots average credit scores by state with a color gradient, and TEXT adds state names. GRADLEGEND provides a legend for the color gradient.
Copied!
proc sgmap mapdata=work.states
maprespdata=work.scoreperstate /* Utilisation du jeu de données autonome */
plotdata=work.plot_data;
esrimap
url='http://services.arcgisonline.com/arcgis/rest/services/Canvas/World_Light_Gray_Base';
choromap _Score_ / mapid=state id=state_fips /* Utilisation de state_fips pour la jointure */
density=1
numlevels=4 leveltype=none
colormodel=( sty greenyellow deepskyblue cornflowerblue beige)
name='choro';
text x=long y=lat text=statename /
textattrs=(size=6pt);
gradlegend 'choro' / title='Average Credit Score'
extractscale;
run;
quit;
1
PROC SGMAP mapdata=work.states
2
maprespdata=work.scoreperstate /* Utilisation du jeu de données autonome */
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.