BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dhrumil_patel
Fluorite | Level 6

I am trying to create basic map of Brazil states, color coded by a count variable indicating number of observations for each state.

 

I have dataset counting the obs for each state name and abbreviation.

 

data listingCnt;
input StateName StateAbbr $32. Obs 8.;
datalines;
Acre   AC  10
Bahia  BA  25
Ceara CE 16 ...other data not shown ;

I'd like to create the map using the following code:

 

proc gmap data=listingCnt map=maps.brazil2;
    id idname;
    choro obs;
run;
quit;

where idname is a variable in maps.brazil2 corresponding to the name of the state in Brazil. However, this code results in the following error message: "Variable idname not found."

 

Using the StateName variable in the input data set as the id variable results in the following message: "ID variable StateName is not found in MAP data set." 

 

So I'm not sure how I correctly specify the id variable here. Any clarification others can provide would be very welcome.

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I think that the Maps.Brazil2 is a feature map and has coordinates for possibly center of state locations but not an actual boundary dataset. See if you have a MAPSGFK library. Possibly there is a dataset with your state boundaries there. It would have the X Y and your state IDNAME values. I don't currently have that library so can't check.

 

 

View solution in original post

4 REPLIES 4
ballardw
Super User

Change the name of your STATENAME variable to IDNAME in Listingcnt or use the rename dataset option to do the same on the datastep.

 

The ID variable needs to be the same name in both the MAP and DATA sets and of the same type numeric or character.

Also you want to make sure that the values are spelled exactly the same with the same capitalization.

dhrumil_patel
Fluorite | Level 6

I think this helps. But now I'm getting an error indicating that the input data set is missing a X and Y variable. 

 

Do I need to specify long/lat coordinates?

ballardw
Super User

I think that the Maps.Brazil2 is a feature map and has coordinates for possibly center of state locations but not an actual boundary dataset. See if you have a MAPSGFK library. Possibly there is a dataset with your state boundaries there. It would have the X Y and your state IDNAME values. I don't currently have that library so can't check.

 

 

Darrell_sas
SAS Employee

I would definitely use MAPSGFK if you can.  It is newer (MAPS cannot be updated) and much easier to use.

 

If you must use the older maps, then something like this will work:

data listingCnt;

length idname $35. StateAbbr $32. Obs 8.;

input idname StateAbbr Obs ;

datalines;

Acre AC 10

Bahia BA 25

Ceara CE 16

;

proc sort data=maps.brazil2 out=brazil2; by idname; run;

data idvar;

merge brazil2 listingcnt; by idname;

run;

data idvar; set idvar; if (stateabbr ne '') then output; run;

proc gmap data=idvar map=maps.brazil;

id id;

choro obs / discrete;

run;

quit;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3026 views
  • 0 likes
  • 3 in conversation