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

 

Hi,

 

I am trying to make a map of Canada (excluding some provinces) and the US using proc gmap.

 

I can create the map and it looks good, but there are random lines running across the map.

 

What am I doing wrong that is causing this?

 

Thank you for your help!

 


DM 'LOG;CLEAR;OUT;CLEAR;'; OPTIONS Missing = '' LS=128 PAGESIZE=36 NONUMBER; 
goptions reset=all border cback=white htitle=12pt htext=10pt;

data map_us; length country $8.;set maps.states;
if state = 02 then delete;
if state = 15 then delete;
if state = 72 then delete;
country = 'US';

data map_can; length country $8.; set maps.canada4;
if province = '60' then delete;
if province = '61' then delete;
if province = '62' then delete;
country = 'CAN';

data mapall(drop=state province);
set map_can map_us;
if country = 'CAN' then staten = province;
if country ne 'CAN' then staten=fipstate(state);
run;


proc gproject
data=mapall out=projmap project=gnomon polelong=100; id staten;
run; quit;

data projmap1; length fill 8.; set projmap; staten = 1;
run;

FILENAME plots "C:\Map Files";
goptions reset=all 
DEVICE=gif 
xpixels=1200
ypixels=1000
transparency 
GSFNAME=plots; 
ods _all_ close;
ods listing; 

proc gmap data=mapall map=projmap1 all;
id staten; choro staten / cdefault = white nolegend uniform;

run; quit;

map with random linesmap with random lines

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Those lines are not actually random. Polygons are drawn in order around a map area identified by the ID variable. So when you set STATEN to 1 for your final data set then everything belongs to the same "polygon". Depending on where one last record for state or province occurs the border continues to the next state/province. Normally the ID would "close" the polygon when the last value of the Id is encountered and start the next polygon with the next area but you overrode that behavior by changing the STATEN to the same value.

 

If the purpose of setting STATEN to 1 was to have uniform color for all the areas then leave your Staten alone and use a format to set all the display values the same.

Try:

data projmap1; length fill 8.; set projmap;;
run;


proc format;
value $staten
other = ' ';
run;
proc gmap data=mapall map=projmap1 all;
id staten; choro staten / cdefault = white nolegend uniform;
format staten $staten. ;
run; quit;
quit;

You can use the format approach to color groups similarly by assigning different values of a variable to the same formatted value.

 


@fastb wrote:

 

Hi,

 

I am trying to make a map of Canada (excluding some provinces) and the US using proc gmap.

 

I can create the map and it looks good, but there are random lines running across the map.

 

What am I doing wrong that is causing this?

 

Thank you for your help!

 


DM 'LOG;CLEAR;OUT;CLEAR;'; OPTIONS Missing = '' LS=128 PAGESIZE=36 NONUMBER; 
goptions reset=all border cback=white htitle=12pt htext=10pt;

data map_us; length country $8.;set maps.states;
if state = 02 then delete;
if state = 15 then delete;
if state = 72 then delete;
country = 'US';

data map_can; length country $8.; set maps.canada4;
if province = '60' then delete;
if province = '61' then delete;
if province = '62' then delete;
country = 'CAN';

data mapall(drop=state province);
set map_can map_us;
if country = 'CAN' then staten = province;
if country ne 'CAN' then staten=fipstate(state);
run;


proc gproject
data=mapall out=projmap project=gnomon polelong=100; id staten;
run; quit;

data projmap1; length fill 8.; set projmap; staten = 1;
run;

FILENAME plots "C:\Map Files";
goptions reset=all 
DEVICE=gif 
xpixels=1200
ypixels=1000
transparency 
GSFNAME=plots; 
ods _all_ close;
ods listing; 

proc gmap data=mapall map=projmap1 all;
id staten; choro staten / cdefault = white nolegend uniform;

run; quit;

map with random linesmap with random lines


 

View solution in original post

2 REPLIES 2
ballardw
Super User

Those lines are not actually random. Polygons are drawn in order around a map area identified by the ID variable. So when you set STATEN to 1 for your final data set then everything belongs to the same "polygon". Depending on where one last record for state or province occurs the border continues to the next state/province. Normally the ID would "close" the polygon when the last value of the Id is encountered and start the next polygon with the next area but you overrode that behavior by changing the STATEN to the same value.

 

If the purpose of setting STATEN to 1 was to have uniform color for all the areas then leave your Staten alone and use a format to set all the display values the same.

Try:

data projmap1; length fill 8.; set projmap;;
run;


proc format;
value $staten
other = ' ';
run;
proc gmap data=mapall map=projmap1 all;
id staten; choro staten / cdefault = white nolegend uniform;
format staten $staten. ;
run; quit;
quit;

You can use the format approach to color groups similarly by assigning different values of a variable to the same formatted value.

 


@fastb wrote:

 

Hi,

 

I am trying to make a map of Canada (excluding some provinces) and the US using proc gmap.

 

I can create the map and it looks good, but there are random lines running across the map.

 

What am I doing wrong that is causing this?

 

Thank you for your help!

 


DM 'LOG;CLEAR;OUT;CLEAR;'; OPTIONS Missing = '' LS=128 PAGESIZE=36 NONUMBER; 
goptions reset=all border cback=white htitle=12pt htext=10pt;

data map_us; length country $8.;set maps.states;
if state = 02 then delete;
if state = 15 then delete;
if state = 72 then delete;
country = 'US';

data map_can; length country $8.; set maps.canada4;
if province = '60' then delete;
if province = '61' then delete;
if province = '62' then delete;
country = 'CAN';

data mapall(drop=state province);
set map_can map_us;
if country = 'CAN' then staten = province;
if country ne 'CAN' then staten=fipstate(state);
run;


proc gproject
data=mapall out=projmap project=gnomon polelong=100; id staten;
run; quit;

data projmap1; length fill 8.; set projmap; staten = 1;
run;

FILENAME plots "C:\Map Files";
goptions reset=all 
DEVICE=gif 
xpixels=1200
ypixels=1000
transparency 
GSFNAME=plots; 
ods _all_ close;
ods listing; 

proc gmap data=mapall map=projmap1 all;
id staten; choro staten / cdefault = white nolegend uniform;

run; quit;

map with random linesmap with random lines


 

GraphGuy
Meteorite | Level 14

In addition to what @ballardw pointed out, I would also suggest using the new maps from the mapsgfk library rather than the (possibly outdated) maps from the old maps library. One caveat there is that SAS only ships 1 Canada map in mapsgfk, therefore you'll have to derive the province map from it (using proc gremove) - that can be a little confusing if you haven't done it before, therefore I'm including some code below:

 

data map_us; set mapsgfk.us_states (where=(statecode not in ('AK' 'HI') and density<=4));
my_id=statecode;
country='US';
run;

data map_canada; set mapsgfk.canada (where=(id1 not in ('CA-60' 'CA-61' 'CA-62') and density<=1));
run;

proc gremove data=map_canada out=map_canada;
by id1;
id id;
run;

data map_canada; set map_canada;
my_id=id1;
country='CA';
run;


data mapall; 
length my_id $8;
set map_us map_canada;
run;

proc sql noprint;
create table mapall_attr as
select unique country, my_id, 1 as fakedata
from mapall;
quit; run;

proc gproject data=mapall out=mapall_proj latlong eastlong degrees project=gnomon;
id country my_id;
run;

pattern1 v=solid color=white;

proc gmap map=mapall_proj data=mapall_attr all;
id my_id;
choro fakedata / levels=1 nolegend coutline=gray55;
run;

canada_us.png

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 583 views
  • 2 likes
  • 3 in conversation