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

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

7 REPLIES 7
tomtang
Calcite | Level 5

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

tomtang
Calcite | Level 5

hi,

in Mike's code,

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

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

art297
Opal | Level 21

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.

tomtang
Calcite | Level 5

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.

art297
Opal | Level 21

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;

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
  • 7 replies
  • 3743 views
  • 0 likes
  • 2 in conversation