BookmarkSubscribeRSS Feed
julie_AF
Calcite | Level 5

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

 

from: https://communities.sas.com/t5/SAS-Communities-Library/Driving-Distances-and-Drive-Times-using-SAS-a...

 

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

5 REPLIES 5
ChrisNZ
Tourmaline | Level 20

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?

julie_AF
Calcite | Level 5

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.

 

ChrisNZ
Tourmaline | Level 20

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.

Ksharp
Super User

Check GEODIST Function 

julie_AF
Calcite | Level 5

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 794 views
  • 1 like
  • 3 in conversation