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-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
  • 3 replies
  • 1306 views
  • 0 likes
  • 3 in conversation