BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hellorc
Obsidian | Level 7

Hello SAS community, might someone please help me with creating a map graph for a country besides USA?

 

So I was going through the example in http://support.sas.com/kb/44/428.html, in which a map of both USA and Mexico is generated. I attempted to modify the code so that it would only contain Mexico, but it was unsuccessful. For example, consider a data:

data have;
input state $ income @@;
datalines;
Aguascalientes 100 
BajaCalifornia 99 
BajaCaliforniaSur 98
Campeche 55
Chiapas 60
Chihuahua 77
Coahuila 51
Colima 66
Durango 78
Guanajuato 66
Guerrero 74
Hidalgo 85
Jalisco 63
México 101
MexicoCity 105
Michoacán 95
Morelos 43
Nayarit 67
NuevoLeón 84
Oaxaca 63
Puebla 53
Querétaro 78
QuintanaRoo 77
SanLuisPotosí 69
Sinaloa 68
Sonora 48
Tabasco 59
Tamaulipas 68
Tlaxcala 77
Veracruz 95
Yucatán 64
Zacatecas 88
;
run;
data have;
set have;
if income <= 70 then incomelevel='low';
else if 70<income<=90 then incomelevel='average';
else if income>90 then incomelevel='high';
run;

I would like to compute just a simple map graph of Mexico, and color the states by incomelevel variable. My attempt:

/* Create a map data set for Mexico */                                                                                                  
data mexico(rename=(long=x lat=y));                                                                                                     
   set maps.mexico(drop=x y);                                                                                                           
run;                                                                                                                                    
                                                                                                                        
/* Project the map data */                                                                                                              
proc gproject data=mexico out=mexico_graph;                                                                                                 
   id id state;                                                                                                                         
run;                                                                                                                                    
quit;                                                                                                                                   
                                                                                                                   
/* Generate the graph */                                                                                                                          
title 'Map of Mexico';                                                                                                         
proc gmap data=have map=mexico_graph;                                                                                                
   id id state;                                                                                                                         
   choro incomelevel/ discrete coutline=graybb;                                                                          
run;                                                                                                                                    
quit;               

Something is just wrong. May I please have some assistance or advice from your expertise? Thank you in advance!

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

First, there is no need to project the map data set. The example you followed did that because the two map data sets needed it.

 

If you look at the Maps.mexico2 data set you will find a variable named IDNAME that has text describing the name of the states along with the ID variable value to go with the text.

 

Your text for State in your Have data set doesn't match that in the Mexico2 set. If you make your text the same you can merge with the Mexico2 set to get the ID along with your values. Or manually adjust the Have set with Id values from Mexico2.

 

If you want the TEXT of the state name to appear then you need to make an annotate data set with the map x,y coordinates where you want the text to appear.

View solution in original post

1 REPLY 1
ballardw
Super User

First, there is no need to project the map data set. The example you followed did that because the two map data sets needed it.

 

If you look at the Maps.mexico2 data set you will find a variable named IDNAME that has text describing the name of the states along with the ID variable value to go with the text.

 

Your text for State in your Have data set doesn't match that in the Mexico2 set. If you make your text the same you can merge with the Mexico2 set to get the ID along with your values. Or manually adjust the Have set with Id values from Mexico2.

 

If you want the TEXT of the state name to appear then you need to make an annotate data set with the map x,y coordinates where you want the text to appear.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 404 views
  • 0 likes
  • 2 in conversation