Hello,
I would like to calculate the actual distance and travel time using Google Map.
I have a table with the GPS coordinates of the cities concerned (latitude, longitude):
Lat1 longLat2 Long2 Long2
I want to calculate the distance between (lat1, long1) and (lat2, long2).
I have made some progress, but I don't know how to output the coordinates in the variable macros like in this example:
"%let ll1=%str(42.691560,-73.827840);
%let ll2=%str(35.805410,-78.797679);
* no changes required below this line;
filename x url "https://www.google.com/maps/dir/&ll1/&ll2/?force=lite";
filename z temp;
data _null_;
infile x recfm=f lrecl=1 end=eof;
file z recfm=f lrecl=1;
input @1 x $char1.;
put @1 x $char1.;
if eof;
call symputx('filesize',_n_);
run;
data _null_;
infile z recfm=f lrecl=&filesize. eof=done;
input @ 'miles' +(-15) @ '"' distance :comma12. text $30.;
units = scan(text,1,'"');
time = scan(text,3,'"');
file print;
put "DRIVING DISTANCE BETWEEN &ll1 AND &ll2 : "
distance units" (TIME: " time ")";
stop;
done:
file print;
put "CANNOT FIND THE DRIVING DISTANCE BETWEEN &ll1 AND &ll2 : " /
"TRY ANOTHER PAIR OF COORDINATES";
stop;
run;
filename x clear;
filename z clear;
"
Even from code given on the link mentioned above, I have a display problem in the result viewers:
DRIVING DISTANCE BETWEEN 42.691560,-73.827840 AND 35.805410,-78.797679 : .
I can't access the web from our sas server, but your passing parameters looks fine.
Also you have no reason to use %str().
What goes wrong?
With regard to the codes written on the site and that it doesn't work for me (the calculation of distance and time is not done), I sent an email to SAS which replied that the macro used was not provided "officially" with SAS tools was not supported by SAS and that the section "Alternative Method", directs you to a pdf containing the coordinates of other authors on the same subject. I think that it is this paper: http://support.sas.com/resources/papers/proceedings12/091-2012.pdf
The article used the web API, however, I don't know and I can't get how to put their macro back in my way.
To pass the parameters from a table, look for the section
* data set with IDs and ADDRESSES;
from the page you mention.
call symput() does the macro variable assignment.
Check GEODIST Function
Geodist function gives the distances as the crow flies and not the road distances.
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!
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.
Ready to level-up your skills? Choose your own adventure.