Data visualization with SAS programming

PROC GMAP: Mapping States of Brazil

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

PROC GMAP: Mapping States of Brazil

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.


Accepted Solutions
Solution
‎06-10-2016 01:44 PM
Super User
Posts: 11,343

Re: PROC GMAP: Mapping States of Brazil

Posted in reply to dhrumil_patel

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


All Replies
Super User
Posts: 11,343

Re: PROC GMAP: Mapping States of Brazil

Posted in reply to dhrumil_patel

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.

Contributor
Posts: 22

Re: PROC GMAP: Mapping States of Brazil

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?

Solution
‎06-10-2016 01:44 PM
Super User
Posts: 11,343

Re: PROC GMAP: Mapping States of Brazil

Posted in reply to dhrumil_patel

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.

 

 

SAS Employee
Posts: 170

Re: PROC GMAP: Mapping States of Brazil

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;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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