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;

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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