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

Hello,

 

I am very new to base SAS, but stumbled upon sgmap and thought that it would be very useful for a research project my department is working on. I would like to plot locations using longitude and latitude data, then calculate and plot distance lines between pairs of locations. Is this possible in University Edition of SAS studio? I have only seen bubble plots without lines using sgmap. I don't currently have access to SAS/graph which I know can do what I want.

 

Thank you,

KellyP

1 ACCEPTED SOLUTION

Accepted Solutions
KellyP
Fluorite | Level 6

Here is how I programmed the lines and distance labels. I will probably adjust the formatting some more, but I am close to what I want.

data maptest;
	set maptes.sheet1;
	format distance comma10.2;
	distance=geodist(lat1, lon1, lat2, lon2, 'M');
	Route+1;
	DistLabel=catx(" ", round(distance, 0.01),"miles");
run;

data map_data_rotate (keep=year Location lat lon distance route DistLabel latmid lonmid);
	set maptest;
	format lat lon 8.4;
	latmid=(lat1+lat2)/2;
	lonmid=(lon1+lon2)/2;
	array lata(2) 8 Lat1 Lat2;
	array lona(2) 8 Lon1 Lon2;
	do i= 1 to 2;
		If lata(i) then lat=lata(i);
		if lona(i) then lon=lona(i);
		if i=1 then location=start_location;
		if i=2 then location=Destination;
		output;
	end;
run;
			
			

title Years 2018 and 2019;

proc sgmap plotdata=map_data_rotate;
    openstreetmap;
			series x=lon y=lat /group=Route ;
			scatter x=lonmid y=latmid /group=Route datalabel=distlabel DATALABELPOS=right DATALABELATTRS=(color=green size=8pt);
			

run;

title Year 2018;
proc sgmap plotdata=map_data_rotate;
    openstreetmap;
    where year=2018;
			series x=lon y=lat /group=Route ;
			scatter x=lonmid y=latmid /group=Route datalabel=distlabel DATALABELPOS=right DATALABELATTRS=(color=green size=8pt);
run;

title Year 2019;
proc sgmap plotdata=map_data_rotate;
    openstreetmap;
    where year=2019;
			series x=lon y=lat /group=Route ;
			scatter x=lonmid y=latmid /group=Route datalabel=distlabel DATALABELPOS=right DATALABELATTRS=(color=green size=8pt);
run;
title;

 

View solution in original post

5 REPLIES 5
Reeza
Super User
SAS Academics on Demand supports SAS/Graph if you need it. Same restrictions as SAS UE.
GraphGuy
Meteorite | Level 14

Here is one way to do it, using Proc SGmap in the latest version of SAS (9.4m6) ...

 

data my_map; set mapsgfk.us_states (where=(statecode='NC'));
run;
data my_map_data; set mapsgfk.us_states_attr (where=(statecode='NC'));
run;


data points;
lat=35.73; long=-80.68; output;
lat=35.82; long=-78.76; output;
distance='distance = '||trim(left(put(geodist(35.73, -80.68, 35.82, -78.76, 'DM'),comma5.0))); output;
run;

 

ods path(prepend) work.templat(update);
proc template;
define style styles.nc_style;
parent=styles.htmlblue;
class graphcolors / 'gdata1'=cornsilk;
end;
run;


ods html style=nc_style;

title1 "North Carolina map, with distance";
proc sgmap maprespdata=my_map_data mapdata=my_map plotdata=points noautolegend;
choromap statecode / mapid=statecode;
scatter x=long y=lat;
series x=long y=lat;
text x=long y=lat text=distance / position=topright textattrs=(color=red size=11pt);
run;

 

sgmap.png

KellyP
Fluorite | Level 6
Thank you! This definitely helped me figure out my program!
KellyP
Fluorite | Level 6

Here is how I programmed the lines and distance labels. I will probably adjust the formatting some more, but I am close to what I want.

data maptest;
	set maptes.sheet1;
	format distance comma10.2;
	distance=geodist(lat1, lon1, lat2, lon2, 'M');
	Route+1;
	DistLabel=catx(" ", round(distance, 0.01),"miles");
run;

data map_data_rotate (keep=year Location lat lon distance route DistLabel latmid lonmid);
	set maptest;
	format lat lon 8.4;
	latmid=(lat1+lat2)/2;
	lonmid=(lon1+lon2)/2;
	array lata(2) 8 Lat1 Lat2;
	array lona(2) 8 Lon1 Lon2;
	do i= 1 to 2;
		If lata(i) then lat=lata(i);
		if lona(i) then lon=lona(i);
		if i=1 then location=start_location;
		if i=2 then location=Destination;
		output;
	end;
run;
			
			

title Years 2018 and 2019;

proc sgmap plotdata=map_data_rotate;
    openstreetmap;
			series x=lon y=lat /group=Route ;
			scatter x=lonmid y=latmid /group=Route datalabel=distlabel DATALABELPOS=right DATALABELATTRS=(color=green size=8pt);
			

run;

title Year 2018;
proc sgmap plotdata=map_data_rotate;
    openstreetmap;
    where year=2018;
			series x=lon y=lat /group=Route ;
			scatter x=lonmid y=latmid /group=Route datalabel=distlabel DATALABELPOS=right DATALABELATTRS=(color=green size=8pt);
run;

title Year 2019;
proc sgmap plotdata=map_data_rotate;
    openstreetmap;
    where year=2019;
			series x=lon y=lat /group=Route ;
			scatter x=lonmid y=latmid /group=Route datalabel=distlabel DATALABELPOS=right DATALABELATTRS=(color=green size=8pt);
run;
title;

 

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
  • 5 replies
  • 1183 views
  • 7 likes
  • 3 in conversation