25
Driving Distances and Times Using SAS® and Google Maps Mike Zdeb University at Albany School of Public Health

Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

Driving Distances and Times Using SAS® and Google Maps

Mike ZdebUniversity at Albany School of Public Health

Page 2: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# WHY ... STUDY OF MOTHERS ANDINFANTS IN NEW YORK STATE

# 1,000+ MOMS AND THREE CLINICS

# WHICH CLINIC IS CLOSEST TO EACH MOM

# WHAT IS THE DRIVE TIME TO THAT CLINIC

Page 3: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# SATISFIED WITH DISTANCE BETWEEN ZIPCENTROIDS ... NOT USING STREETADDRESS

# USE SASHELP.ZIPCODE TO FIND LATITUDEAND LONGITUDE OF CENTROIDS FORMOMS AND CLINICS

# WHERE ARE CLINICS AND MOMS

Page 4: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population
Page 5: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# EASY TO CALCULATE STRAIGHT LINEDISTANCE

# FUNCTIONS IN V9.2

GEODIST ... SPECIFY LATITUDE ANDLONGITUDE FOR TWO LOCATIONS

ZIPCITYDISTANCE ... SPECIFY TWO ZIPS(ACCESSES LAT/LONG IN SASHELP.ZIPCODE)

Page 6: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# PRIOR TO V9.2

HAVERSINE FORMULA

"... GREAT‐CIRCLE DISTANCES BETWEEN TWOPOINTS ON A SPHERE FROM THEIRLONGITUDES AND LATITUDES ..."

V9.2 FUNCTIONS USE THE VINCENTYFORMULA (MORE ACCURATE AND MORECOMPLICATED THAN HAVERSINE)

Page 7: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population
Page 8: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# DRIVING DISTANCE ... 383 MILES# DRIVING TIME ... 6 HOURS 45 MINUTES 

Page 9: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# IN DIRECTIONS BOXCLICK ON LINK

# COPY LINK AND IT LOOKS AS FOLLOWS ...

https://maps.google.com/maps?saddr=Albany,+NY&daddr=Toronto,+ON&hl=en&ll=43.237199,‐76.442871&spn=4.554025,7.003784&sll=42.652579,‐73.756232&sspn=0.287351,0.437393&geocode=FaPTigIduJGa‐ylL‐0_MNAreiTHEKOegEmOh4Q%3BFWoYmgIdcLVE‐ymlO8bXkMvUiTF3xLQqUFU1Mg&mra=ls&t=m&z=8

# SHORT URL ... http://goo.gl/maps/w3K3

Page 10: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# MINIMUM INFO FOR GOOGLE MAP

Page 11: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# MORE DETAILS ON THE SAS COMMUNITYWEB SITE ...  SEARCH FOR "drivingdistance"

Page 12: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population
Page 13: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population
Page 14: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

%let ll1=%str(42.73,‐73.80);%let ll2=%str(43.73,‐79.38); * URL access method;filename x url "http://maps.google.com/maps?daddr=&ll2.%nrstr(&saddr)=&ll1";filename z temp; * store web page contents in file 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;

Page 15: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

* find distance and time in file TEMP;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 &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;

* clear file names;filename x; filename z;

Page 16: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# POSTAL CODES

Page 17: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

* enter two zip codes;%let z1=12203;%let z2=M4W1A1; filename x url"http://maps.google.com/maps?daddr=&z2.%nrstr(&saddr)=&z1";filename z temp; 

<SAME SAS CODE AS WITH LAT/LONG>

DRIVING DISTANCE BETWEEN 12203 ANDM4W1A1 : 379 mi  (TIME: 6 hours 41 mins )

Page 18: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

EXAMPLE APPLICATION ... FIND DRIVINGDISTANCE AND TIME TO ZIP 12203 (CITY OFALBANY) FOR POPULATION IN COUNTIES THATSURROUND ALBANY COUNTY

# ZIP 12203 COULD BE THE LOCATION OF AHOSPITAL, STORE, ETC.

Page 19: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population
Page 20: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# USE SAS AND GOOGLE MAPS TO FINDDRIVING DISTANCE AND TIME

# MERGE DATA WITH ZIP‐SPECIFICPOPULATION DATA

# USE PROC UNIVARIATE TO FINDPERCENTAGE OF POPULATION WITHVARIOUS DISTANCES AND TIMES TO ZIP12203

Page 21: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# 50% OF POPULATION 17.1 MILES AND 23MINUTES FROM ZIP 12203

Page 22: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# Work was funded in part by NIH grantHHSN267200700019C from the EuniceKennedy Shriver National Institute ofChild Health and Human Development

Page 23: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population

# ANOTHER APPROACH ...

Page 24: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population
Page 25: Driving Distances and Times Using SAS and Google Maps Group Presentati… · # use sas and google maps to find driving distance and time # merge data with zip‐specific population