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

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

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

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

3 REPLIES 3
JeffP
SAS Employee

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

GraphGuy
Meteorite | Level 14

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;

Reeza
Super User

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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

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