Data visualization with SAS programming

Gaps in Legend using Proc GMAP

Accepted Solution Solved
Reply
Super User
Posts: 19,126
Accepted Solution

Gaps in Legend using Proc GMAP

I'm creating a map using GMAP and the variable being plotted is continuous and then formatted using a proc format.

Some of the ranges in the format are not within the dataset and usually you insert fake values to get around this as per the example I've linked to. However this isn't working for me, and I was wondering if there was another way to get all the legend values to show.

ie legend values are:

0-9

10-19

20-29

30-39

40-49

but what ends up showing on the map

is

0-9

10-19

40-49

because there is no 20-39. I'd like to force those values in the legend.

http://communities.sas.com/message/33948#33948


Accepted Solutions
Solution
‎09-28-2011 09:00 AM
SAS Employee
Posts: 980

Gaps in Legend using Proc GMAP

Whereas in Gchart, you generally have to add "fake obsns" to your data to get all the possible values in the legend, Gmap has an extra feature/option that I find useful for this -- the midpoints= option.

You can specify all the possible values to make sure they're in the legend (even if they're not in the data).  Here is a simple example - note that 'C' is not in my data, but it is in the map legend:

proc sql;

create table foo as select unique state  from maps.us;

quit; run;

data foo; set foo;

if state<25 then myval='A';

else if state<50 then myval='B';

else myval='D';

run;

proc gmap data=foo map=maps.us;

id state;

choro myval / midpoints='A' 'B' 'C' 'D';

run;

View solution in original post


All Replies
SAS Employee
Posts: 2

Re: Gaps in Legend using Proc GMAP

Do you mind sharing your SAS code?  Or at least the portion where you are adding the 'fake' values and the proc gmap statement.

Solution
‎09-28-2011 09:00 AM
SAS Employee
Posts: 980

Gaps in Legend using Proc GMAP

Whereas in Gchart, you generally have to add "fake obsns" to your data to get all the possible values in the legend, Gmap has an extra feature/option that I find useful for this -- the midpoints= option.

You can specify all the possible values to make sure they're in the legend (even if they're not in the data).  Here is a simple example - note that 'C' is not in my data, but it is in the map legend:

proc sql;

create table foo as select unique state  from maps.us;

quit; run;

data foo; set foo;

if state<25 then myval='A';

else if state<50 then myval='B';

else myval='D';

run;

proc gmap data=foo map=maps.us;

id state;

choro myval / midpoints='A' 'B' 'C' 'D';

run;

Super User
Posts: 19,126

Re: Gaps in Legend using Proc GMAP

The code is below and Robs suggestions of using midpoints was the correct one. Becuase I'm using numeric values it was midpoints=0 to 1 by 0.1 that got it working without the fake data points.

Thanks!

data fake_map_data;

    length region $10.;

    lha='';

    do i=1 to 100 by 10;

    pop_pct3=i/100;

    pop_pct15=i/100;

    pop_pct16=i/100;

    output;

    end;

drop i;

run;

data region_data2;

    set region_data fake_map_data;

run;

legend1 label=none across=1 position=(right middle);

proc gmap data=region_data2 map=map_data;

    id region;

    choro pop_pct3 / discrete coutline=black midpoints=0 to 1 by 0.1 legend=legend1;

    format pop_pct3 rate.;

run;

quit;

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 329 views
  • 0 likes
  • 3 in conversation