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

Hello,

When I copy and run today sas code from “http://www.sascommunity.org/wiki/Driving_Distances_and_Drive_Times_using_SAS_and_Google_Maps

about using two city’s zip code or latitude/longitude to calculate driving time.

SAS appear error in the log like” Hostname ddr=20500 &saddr=12203 not found.“ or “Hostname ddr=35.805410,-78.797679&saddr=42.691560,-73.827840 not found. “

May I consult what is the problem? It seems URL is still “http://maps.google.com/maps?daddr=20005&saddr=12203

Thank you so much for your time.

Xiaoran

My copy code is as follows:

* enter two zip codes;

%let z1=12203;

%let z2=20500;

* no changes required below this line;

filename x url "http://maps.google.com/maps?daddr=&z2.%nrstr(&saddr)=&z1";

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 @ '<div class="altroute-rcol altroute-info"> <span>'  @;

input text $50.;

distance = input(scan(text,1," "),comma12.);

units = scan(text,2,"< ");

time  = scan(text,5,"<>");

file print;

put "DRIVING DISTANCE BETWEEN &z1 AND &z2 : "

  distance units" (TIME: " time ")";

stop;

done:

file print;

put "CANNOT FIND THE DISTANCE OR TIME BETWEEN &z1 AND &z2, TRY ANOTHER COMBINATION";

run;

filename x clear;

filename z clear;

1 ACCEPTED SOLUTION

Accepted Solutions
AncaTilea
Pyrite | Level 9

I think it has to do with the SAS version.

I am using SAS 9.3, what version are you using?

View solution in original post

13 REPLIES 13
AncaTilea
Pyrite | Level 9

Hi.

Interesting problem.

I copied/pasted your code from this posting in my SAS interactive, and it didn't run. I went to the sasCommunity website, copied/pasted the code from there (which I know it's the same code you have) and it ran!

I get this:

DRIVING DISTANCE BETWEEN 12203 AND 20500 : 373 mi  (TIME: 5 hours 54 mins )

When I ran your posted code I get this:

CANNOT FIND THE DISTANCE OR TIME BETWEEN 12203 AND 20500, TRY ANOTHER COMBINATION

The code that is working:

* enter two zip codes;

%let z1=12203;

%let z2=20500;

* no changes required below this line;

filename x url "http://maps.google.com/maps?daddr=&z2.%nrstr(&saddr)=&z1";

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 @ '<div class="altroute-rcol altroute-info">  <span>'  @;

input text $50.;

distance = input(scan(text,1," "),comma12.);

units    = scan(text,2,"< ");

time     = scan(text,5,"<>");

file print;

put "DRIVING DISTANCE BETWEEN &z1 AND &z2 : "

     distance units" (TIME: " time ")";

stop;

done:

file print;

put "CANNOT FIND THE DISTANCE OR TIME BETWEEN &z1 AND &z2, TRY ANOTHER COMBINATION";

run;

filename x clear;

filename z clear;

The code that is not working:

* enter two zip codes;

%let z1=12203;

%let z2=20500;

* no changes required below this line;

filename x url "http://maps.google.com/maps?daddr=&z2.%nrstr(&saddr)=&z1";

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 @ '<div class = "altroute-rcol altroute-info"> <span>'  @;

input text $50.;

distance = input(scan(text, 1, " "), comma12.);

units = scan(text,2,"< ");

time  = scan(text,5,"<>");

file print;

put "DRIVING DISTANCE BETWEEN &z1 AND &z2 : "

  distance units" (TIME: " time ")";

stop;

done:

file print;

put "CANNOT FIND THE DISTANCE OR TIME BETWEEN &z1 AND &z2, TRY ANOTHER COMBINATION";

run;

filename x clear;

filename z clear;

What is the difference?????

huan0236
Calcite | Level 5

Hi, Anca:

Thanks for your kind help.

Will you please tell me the website address where you get the program that works? Because I copy your program and still find it does not work.

The same problem saying in log "Hostname ddr=20500&saddr=12203 not found."..

Thanks a lot.

Best,

Xiaoran

AncaTilea
Pyrite | Level 9

I think it has to do with the SAS version.

I am using SAS 9.3, what version are you using?

huan0236
Calcite | Level 5

Maybe...I am still trying to figure out . Thanks.

AncaTilea
Pyrite | Level 9

I am fairly sure it has to do with SAS 9.2. vs. 9.3

huan0236
Calcite | Level 5

Yes, I think you are quite right. I am using sas 9.2 right now.

Thanks a lot! Anca.

Best,

Xiaoran

AncaTilea
Pyrite | Level 9

When I run it on SAS 9.2:

NOTE: Unable to connect to host ddr=20500&saddr=12203. Check validity of host name.

ERROR: Hostname ddr=20500&saddr=12203 not found.

When I run it in SAS 9.3:

The SAS System09:06 Thursday, December 19, 2013   1

DRIVING DISTANCE BETWEEN 12203 AND 20500 : 373 mi  (TIME: 5 hours 54 mins )

This is where I got the code from:

Driving Distances and Drive Times using SAS and Google Maps - sasCommunity

starting from:

DRIVING DISTANCE AND DRIVE TIME onwards.


Smiley Happy

MikeZdeb
Rhodochrosite | Level 12

Hi.  If you are using an early version of V9.2, there might be a problem ...

Problem Note 34098: SAS® is unable to connect to the host when specifying the host name while using the FTP/URL/Socket/EMAIL FILENAME engine

http://support.sas.com/kb/34/098.html

If you look at the end of my posting where you got the code ...

Driving Distances and Drive Times using SAS and Google Maps - sasCommunity

you will notice that it says ...

NOTE ... There is a SAS problem note "Problem Note 34098: SAS® is unable to connect to the host when specifying the host name while using... related to using the URL access method. If the code posted here produces an error message about not being able to connect to Google Maps, you may have to apply a HOTFIX to your SAS installation.

huan0236
Calcite | Level 5

Hi, Mike. Lucky to have your help on SAS 9.2. I think Problem Note 34098: is the problem that matter. And your link of HOTFIX is exactly the solution for it.

But after trying for a while, I am not sure why double click the f9ba26wn.exe and set up has not made SAS 9.2 ERROR changed, like "HOSTNAME host name NOT FOUND". And I cannot found the file of "tkitcp.dll" which is indicated to be installed in "f9ba26wn.txt". Seems strange...

MikeZdeb
Rhodochrosite | Level 12

Hi .. that's my SAS code from the SAS Community page.  I think that the problem has nothing to do with 9.2 versus 9.3 (I wrote the original stuff when 9.3 had not been released).

I cut/pasted the code you posted and it did not work for me in 9.3.  I cut/pasted the code from SAS Community and it did work

There is a minor difference between what you posted and what's on the web site.  In the second data step ... your posted code has this line ...

input @ '<div class="altroute-rcol altroute-info"> <span>'  @;

while my posted code has this line ..

input @ '<div class="altroute-rcol altroute-info">  <span>'  @;

Your code has TWO spaces before the text <span> ... there should be THREE spaces (as in the code on the web site).

huan0236
Calcite | Level 5

Hi, Mike. Today I try the code on a computer which has SAS 9.3, and it works! I think you find a very importance difference that on my original pasted code,

"input @ '<div class="altroute-rcol altroute-info"> <span>'  @;" there is not enough space before <span>. If we do so on SAS 9.3 with missed space, it wil turn out the result to be "CANNOT FIND THE DISTANCE OR TIME BETWEEN 12203 AND 20500, TRY ANOTHER COMBINATION".

Thank you for your help! I've learn a lot.

By they way, the missing space problem happens seems randomly...I do not know why, I copy 5 times, one time would lost the space....

dcortell
Pyrite | Level 9

Hi guys, from the same example (but different code from the same page) I get following errors

 

ERROR: Host name www.google.com not found.

ERROR 24-2: Invalid value for the LRECL option.

code is below

 

* data set with IDs and ADDRESSES;
data addresses;
length addr1 addr2 $50;
input 
@01 id     $5.
@10 addr1  $30.
@40 addr2  $30.
;
zip = input(scan(addr1,-1),5.);
set sashelp.zipcode (keep=zip poname statecode) key=zip / unique;
addr1 = catx(' ',catx(',+',scan(addr1,1,','),poname,statecode),zip);
zip = input(scan(addr2,-1),5.);
set sashelp.zipcode (keep=zip poname statecode) key=zip / unique;
addr2 = catx(' ',catx(',+',scan(addr2,1,','),poname,statecode),zip);
keep id addr: ;
datalines;
12345    59 LENOX AVE, 12203            1 UNIVERSITY PL, 12144
98989    616 COSBY ROAD, 13502          59 LENOX AVE, 12203
99999    59 Lenox Ave, 12203            SAS Campus Drive, 27513
87878    370 Frederick St, 94117        2129 N St NW, 20037
;
 
* place number of addresses in a macro variable;
data _null_;
call symputx('naddr',obs);
stop;
set addresses 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;
 
* use a loop within a macro to access Google Maps multiple time;
%macro distance_time;
%do j=1 %to &naddr;
data _null_;
nrec = &j;
set addresses point=nrec;
call symputx('id',id);
call symputx('a1',translate(trim(addr1),'+',' '));
call symputx('a2',translate(trim(addr2),'+',' '));
stop;
stop;
run;
 
filename x url "https://www.google.com/maps/dir/&a1/&a2/?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 temp;
length addr1 addr2 $50;
id = "&id";
addr1 = upcase(translate("&a1",' ','+'));
addr2 = upcase(translate("&a2",' ','+'));
 
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 id addr1 addr2 distance units time;
label
addr1 = 'ADDRESS #1'
addr2 = 'ADDRESS #2'
id    = 'ID #'
distance = 'DISTANCE (MILES)'
time     = 'TIME (HR:MIN)'
;
stop;
done:
output;
run;
 
filename x clear;
filename z clear;
 
proc append base=distance_time data=temp;
run;
%end;
%mend;
 
* use the macro;
%distance_time;
 
* 
add the distance between ZIP centroids 
(should be "in same ballpark" as driving distance)
;
data distance_time;
set distance_time;
* ZIP should be LAST entry in the addresses;
zip_city = zipcitydistance(scan(addr1,-1),scan(addr2,-1));
label zip_city = 'ZIPCITYDISTANCE FUNCTION';
run;
 
title "DRIVING DISTANCE AND TIMES";
proc print data=distance_time label noobs;
var id addr1 addr2 distance time zip_city;
format time time6.;
run;

 Any idea???

ysusanto41
Calcite | Level 5

Hi Mike, First of all, I would like to thank you for writing this code, it does help a lot.

 

I am facing an issue while running this code - i used to be able to run with no problem, not there is an error coming:

 

ERROR: Cannot load SSL support.

 

Then later follow by:

 

31

32

33 data _null_;

34

35 infile z recfm=f lrecl=&filesize. eof=done;

-

24

WARNING: Apparent symbolic reference FILESIZE not resolved.

ERROR 24-2: Invalid value for the LRECL option.

 

 

What does this error mean?

 

I am using SAS 9.3. Thank you so much for your guidance.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 13 replies
  • 2292 views
  • 4 likes
  • 5 in conversation