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

Using code I aquired a few years ago from a paper by Mike Zdeb, which get drive distances and times with Google Maps.

Have run it often since then.

Recently am getting  a 'Connection reset by peer' error.    Don't think it's a SAS issue per se so I'm wondering if anyone has any

insight regarding who or how to contact at Google.

 

___________________________________________________________________________________________________

 

%let z1=35294;

* data set with zip codes (98765 is an invalid zip code);
data zip_info;
input zip @@;
datalines;
35244 35209 35007
;

* place number of zip in a macro variable;
data _null_;
call symputx('nzips',obs);
stop;
set zip_info nobs=obs;
run;

* delete any data set named DISTANCE_TIME that might exist in the WORK library;
proc datasets lib=work nolist;
delete distance_time;
quit;

* create a macro that contains a loop to access Google Maps multiple time;
%macro distance_time;
%do j=1 %to &nzips;
data _null_;
nrec = &j;
set zip_info point=nrec;
call symputx('z2',put(zip,z5.));
stop;
run;

filename x url "https://www.google.com/maps/dir/&z1/&z2/?force=lite";
filename z temp;

* same technique used in the example with two zip codes;
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;

* drive time as a numeric variable;
data temp;
retain zip &z2;
infile z recfm=f lrecl=&filesize. eof=done;
input @ 'miles' +(-15) @ '"' distance :comma12. text $30.;
units = scan(text,1,'"');
text = scan(text,3,'"');

* convert times to seconds;
select;
* combine days and hours;
when (find(text,'d') ne 0) time = sum(86400*input(scan(text,1,' '),best.),
3600*input(scan(text,3,' '),best.));
* combine hours and minutes;
when (find(text,'h') ne 0) time = sum(3600*input(scan(text,1,' '),best.),
60*input(scan(text,3,' '),best.));
* just minutes;
otherwise time = 60*input(scan(text,1,' '),best.);
end;

output;
keep zip distance units time;
stop;
done:
output;
run;

filename x clear;
filename z clear;

* add an observation to the data set DISTANCE_TIME;
proc append base=distance_time data=temp;
run;
%end;
%mend;

* use the macro;
%distance_time;

* add the straight line distance to the data set;
data distance_time;
set distance_time;
zip_city = zipcitydistance(12203,zip);
run;

proc print data=distance_time;
format zip z5. distance comma6. time time6.;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Google may change its terms of service at any time. Especially for a free service. It might be different if you paid.

Unsure about how to contact them about his, sorry.

An option if you want to space the calls is to use call sleep().

View solution in original post

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

Google will refuse the connection if the same IP address queries its services too many times or without sufficient delay between the queries.

uabcms
Calcite | Level 5

Okay, but I'm not running this code any more frequently or with any more observations than I have in the past 3 years.

I realize I may be outside of the SAS realm but are you familiar with how to get in touch with Google regarding this issue?

ChrisNZ
Tourmaline | Level 20

Google may change its terms of service at any time. Especially for a free service. It might be different if you paid.

Unsure about how to contact them about his, sorry.

An option if you want to space the calls is to use call sleep().

uabcms
Calcite | Level 5

Appreciate your input

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
  • 4 replies
  • 2445 views
  • 1 like
  • 2 in conversation