how to use filename and infile statement to extract goole maps web information

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

how to use filename and infile statement to extract goole maps web information

Hi, I'm currently reading Mike Zdeb's one paper. "Driving Distances and Times Using SAS and Google Maps".  I want to know how to extract all goole maps web source information into one variable in a SAS dataset using filename and infile statement. thanks


Accepted Solutions
Solution
‎11-15-2011 05:45 PM
PROC Star
Posts: 7,492

how to use filename and infile statement to extract goole maps web information

Using code based on Mike's paper, but slightly revised, you could get distance and time with:

* 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 want;

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

  input @ "distance:'" @;

  input text $50.;

  distance = input(scan(text,1,"'"),$20.);

  time     = input(scan(text,3,"'"),$20.);

  output;

  stop;

  done:

run;

filename x clear;

filename z clear;

View solution in original post


All Replies
PROC Star
Posts: 7,492

how to use filename and infile statement to extract goole maps web information

Does Mike's sasCommunity.org page on the topic provide what you are looking for?:

http://www.sascommunity.org/wiki/Driving_Distances_and_Drive_Times_using_SAS_and_Google_Maps

Occasional Contributor
Posts: 10

how to use filename and infile statement to extract goole maps web information

Hi,

I have that paper. I want to know how to extract all goole maps web source information into one variable in a SAS dataset?

for example, in mike's code

* enter two zip codes;

%let z1=12203;

%let z2=27513;

* no changes required below this line;

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

data drive;

retain zip1 &z1 zip2 &z2;

infile x lrecl=32000 pad;

......

how to input all information from x into one variable in sas dataset?

Thanks

Occasional Contributor
Posts: 10

how to use filename and infile statement to extract goole maps web information

hi,

in Mike's code,

loc = find(_infile_,'dditd>');

but i can't find 'dditd>' in the source information.

PROC Star
Posts: 7,492

how to use filename and infile statement to extract goole maps web information

I know Mike mentioned that string in his paper, but I don't think it is still used on the current Google Maps' page.  You can search for such strings as:

distance:'

time:'

summary:'

the single quotes at the end of those strings are necessary to be part of the string and the fields appear to be separated by commas.

Occasional Contributor
Posts: 10

how to use filename and infile statement to extract goole maps web information

Hi,

My logic is

step 1. extract whole goole map web information into sigle variable in SAS dataset.

step 2. use find or substr function to search target string and then get the distance and time information.

Now, I dont know how to extract whole goole map web information into sigle variable in SAS dataset.

Are you able to show me some sample coding for that?

much appreciated.

Solution
‎11-15-2011 05:45 PM
PROC Star
Posts: 7,492

how to use filename and infile statement to extract goole maps web information

Using code based on Mike's paper, but slightly revised, you could get distance and time with:

* 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 want;

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

  input @ "distance:'" @;

  input text $50.;

  distance = input(scan(text,1,"'"),$20.);

  time     = input(scan(text,3,"'"),$20.);

  output;

  stop;

  done:

run;

filename x clear;

filename z clear;

Occasional Contributor
Posts: 10

how to use filename and infile statement to extract goole maps web information

Hi,

Thank you so much.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 3098 views
  • 0 likes
  • 2 in conversation