Calcite | Level 5

## Driving distance and drive times based on GPS coordinates

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 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 : .

5 REPLIES 5
Tourmaline | Level 20

## Re: Driving distance and drive times based on GPS coordinates

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?

Calcite | Level 5

## Re: Driving distance and drive times based on GPS coordinates

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.

Tourmaline | Level 20

## Re: Driving distance and drive times based on GPS coordinates

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.

Super User

## Re: Driving distance and drive times based on GPS coordinates

Check GEODIST Function

Calcite | Level 5

## Re: Driving distance and drive times based on GPS coordinates

Geodist function gives the distances as the crow flies and not the road distances.

Discussion stats
• 5 replies
• 794 views
• 1 like
• 3 in conversation