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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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