Hi,
I should estimate the travel time through SAS and google map, but I can’t.
I’m studying a paper (http://support.sas.com/resources/papers/proceedings10/050-2010.pdf) and the forum (https://communities.sas.com/t5/SAS-Communities-Library/Driving-Distances-and-Drive-Times-using-SAS-a...; https://communities.sas.com/t5/SAS-Communities-Library/Driving-Distances-and-Drive-Times-using-SAS-a...) about the travel time.
I got a API KEY from the google cloud (https://console.cloud.google.com/apis/credentials?project=named-archway-265913). In particular, I'm trying to execute these commands in sas , but they don’t work.
how should I connect SAS to google Maps?
Could you help me understand where I'm wrong in the syntax?
Thank you in advance,
Alessandra
Code extracted from the docx by @Kurt_Bremser:
/*
https://communities.sas.com/t5/SAS-Communities-Library/Driving-Distances-and-Drive-Times-using-SAS-and-Google-Maps/ta-p/475839
A macro version of the above that would find the distance from a specified location to a series of other locations with all locations
in terms of latitude and longitude might look as follows. The example uses a random sample of locations from the data set SASHELP.ZIPCODE
and finds distances and times to each sample observation from the centroid of zip 12203.*/
* lat/long of first location;
* lat/long of first location;
%let ll1=%str(42.691560,-73.827840);
%let key = AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0;
/*Utilizza questa chiave nell'applicazione passandola con il parametro key=API_KEY
https://console.cloud.google.com/apis/credentials?_ga=2.217755218.-512770767.1579693703&project=named-archway-265913&folder&organizationId*/
*/
*
create a data set with locations specified in latitude and longitude
a random sample of 5 observations from SASHELP.ZIPCODE
use SEED=0 to get a new sample each time program is run
;
proc surveyselect data=sashelp.zipcode (keep=zip city statecode x y)
out=lat_long sampsize=5 seed=0;
run;
*
place number of zip in a macro variable
in this example you know it is 5
but you might not know in another use of the SAS code
;
data _null_;
call symputx('nlls',obs);
stop;
set lat_long nobs=obs;
run;
* create a macro that contains a loop to access Google Maps multiple time;
%macro distance_time;
* delete any data set named DISTANCE_TIME that might exist in the WORK library;
proc datasets lib=work nolist;
delete distance_time;
quit;
%do j=1 %to &nlls;
data _null_;
nrec = &j;
set lat_long point=nrec;
call symputx('ll2',catx(',',y,x));
stop;
run;
* lat/long of centroid of zip 12203 hard-coded as part of the URL;
filename x url "https://www.google.com/maps/api/directions/json?origin=&ll1&destination=&ll2&key=&Key";
/*https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&key=YOUR_API_KEY */
filename z temp;
* same technique used in the example with a pair of lat/long coodinates;
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;
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 distance 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 variables from original data set to new data set distance_time
use geodist function to calculate straight line distance
;
data distance_time;
set distance_time;
set lat_long point=_n_;
straight_line = round(geodist(&ll1,-73.827840,y,x,'DM'), 0.01);
run;
proc print data=distance_time noobs label;
var x y time distance straight_line zip city statecode;
format zip z5. time time6. ;
run;
Please post the log that you get (copy/paste into a window opened with the {i} button).
this is the log. Thanks
1 The SAS System 14:16 Wednesday, January 29, 2020
1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='3_Distanza_tempo.sas';
4 %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project';
5 %LET _CLIENTPROJECTPATH='';
6 %LET _CLIENTPROJECTPATHHOST='';
7 %LET _CLIENTPROJECTNAME='';
8 %LET _SASPROGRAMFILE='X:\ISTAT\LINEE_DI_ATTIVITA_2019\Aree interne\prg\distanza\3_Distanza_tempo.sas';
9 %LET _SASPROGRAMFILEHOST='ROSSI';
10
11 ODS _ALL_ CLOSE;
12 OPTIONS DEV=SVG;
13 GOPTIONS XPIXELS=0 YPIXELS=0;
14 %macro HTML5AccessibleGraphSupported;
15 %if %_SAS_VERCOMP(9, 4, 4) >= 0 %then ACCESSIBLE_GRAPH;
16 %mend;
17 FILENAME EGHTML TEMP;
18 ODS HTML5(ID=EGHTML) FILE=EGHTML
19 OPTIONS(BITMAP_MODE='INLINE')
20 %HTML5AccessibleGraphSupported
21 ENCODING='utf-8'
22 STYLE=HtmlBlue
23 NOGTITLE
24 NOGFOOTNOTE
25 GPATH=&sasworklocation
26 ;
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
27
28 %let ll1=%str(42.691560,-73.827840);
29 %let key = AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0;
30
31 *
32 create a data set with locations specified in latitude and longitude
33 a random sample of 5 observations from SASHELP.ZIPCODE
34 use SEED=0 to get a new sample each time program is run
35 ;
36
37 proc surveyselect data=sashelp.zipcode (keep=zip city statecode x y)
38 out=lat_long sampsize=5 seed=0;
39 run;
NOTE: The data set WORK.LAT_LONG has 5 observations and 5 variables.
NOTE: PROCEDURE SURVEYSELECT ha utilizzato (tempo totale di elaborazione):
real time 0.08 seconds
cpu time 0.09 seconds
40
41 *
42 place number of zip in a macro variable
43 in this example you know it is 5
44 but you might not know in another use of the SAS code
45 ;
46 data _null_;
47 call symputx('nlls',obs);
48 stop;
2 The SAS System 14:16 Wednesday, January 29, 2020
49 set lat_long nobs=obs;
50 run;
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
51
52 * create a macro that contains a loop to access Google Maps multiple time;
53 %macro distance_time;
54
55 * delete any data set named DISTANCE_TIME that might exist in the WORK library;
56 proc datasets lib=work nolist;
57 delete distance_time;
58 quit;
59
60 %do j=1 %to &nlls;
61 data _null_;
62 nrec = &j;
63 set lat_long point=nrec;
64 call symputx('ll2',catx(',',y,x));
65 stop;
66 run;
67
68 * lat/long of centroid of zip 12203 hard-coded as part of the URL;
69 filename x url "https://www.google.com/maps/api/directions/json?origin=&ll1&destination=&ll2&key=&Key";
70 filename z temp;
71
72 * same technique used in the example with a pair of lat/long coodinates;
73 data _null_;
74 infile x recfm=f lrecl=1 end=eof;
75 file z recfm=f lrecl=1;
76 input @1 x $char1.;
77 put @1 x $char1.;
78 if eof;
79 call symputx('filesize',_n_);
80 run;
81
82 * drive time as a numeric variable;
83 data temp;
84 infile z recfm=f lrecl=&filesize. eof=done;
85 input @ 'miles' +(-15) @ '"' distance :comma12. text $30.;
86 units = scan(text,1,'"');
87 text = scan(text,3,'"');
88 * convert times to seconds;
89 select;
90 * combine days and hours;
91 when (find(text,'d') ne 0) time = sum(86400*input(scan(text,1,' '),best.),
92 3600*input(scan(text,3,' '),best.));
93 * combine hours and minutes;
94 when (find(text,'h') ne 0) time = sum(3600*input(scan(text,1,' '),best.),
95 60*input(scan(text,3,' '),best.));
96 * just minutes;
97 otherwise time = 60*input(scan(text,1,' '),best.);
98 end;
99 output;
100 keep distance time;
3 The SAS System 14:16 Wednesday, January 29, 2020
101 stop;
102 done:
103 output;
104 run;
105
106 filename x clear;
107 filename z clear;
108
109 * add an observation to the data set DISTANCE_TIME;
110 proc append base=distance_time data=temp;
111 run;
112 %end;
113 %mend;
114
115 * use the macro;
116 %distance_time;
NOTE: Deleting WORK.DISTANCE_TIME (memtype=DATA).
NOTE: PROCEDURE DATASETS ha utilizzato (tempo totale di elaborazione):
real time 0.02 seconds
cpu time 0.00 seconds
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
NOTE: The infile X is:
Filename=https://www.google.com/maps/api/directions/json?origin=42.691560,-73.827840&destination=33.338834,-8...
uS_QMZlitN9RwRhRT7IbaT4vq8T5P0=AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0,
Local Host Name=Rossi,
Local Host IP addr=fe80::10d0:1421:f87:de32%13,
Service Hostname Name=lhr25s09-in-f164.1e100.net,
Service IP addr=216.58.208.164,
Service Name=N/A,Service Portno=443,Lrecl=1,
Recfm=Fixed
NOTE: The file Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-9324-7be0aa8a\contents\SAS Temporary
Files\_TD6628_ROSSI_\#LN00035,
RECFM=F,LRECL=1,Dimensione (byte)=0,
Ultima modifica=29 gennaio 2020 14:22:22,
Create Time=29 gennaio 2020 14:22:22
NOTE: 236 records were read from the infile X.
NOTE: 236 records were written to the file Z.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.27 seconds
cpu time 0.00 seconds
4 The SAS System 14:16 Wednesday, January 29, 2020
NOTE: The infile Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-9324-7be0aa8a\contents\SAS Temporary
Files\_TD6628_ROSSI_\#LN00035,
RECFM=F,LRECL=236,Dimensione (byte)=236,
Ultima modifica=29 gennaio 2020 14:22:22,
Create Time=29 gennaio 2020 14:22:22
NOTE: 1 record was read from the infile Z.
NOTE: SAS went to a new line when INPUT @'CHARACTER_STRING' scanned past the end of a line.
NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.01 seconds
cpu time 0.00 seconds
NOTE: Fileref X has been deassigned.
NOTE: Fileref Z has been deassigned.
NOTE: Appending WORK.TEMP a WORK.DISTANCE_TIME.
NOTE: BASE data set does not exist. DATA file is being copied to BASE file.
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: The data set WORK.DISTANCE_TIME has 1 observations and 2 variables.
NOTE: PROCEDURE APPEND ha utilizzato (tempo totale di elaborazione):
real time 0.01 seconds
cpu time 0.00 seconds
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
NOTE: The infile X is:
Filename=https://www.google.com/maps/api/directions/json?origin=42.691560,-73.827840&destination=37.130336,-8...
uS_QMZlitN9RwRhRT7IbaT4vq8T5P0=AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0,
Local Host Name=Rossi,
Local Host IP addr=fe80::10d0:1421:f87:de32%13,
Service Hostname Name=lhr25s09-in-f164.1e100.net,
Service IP addr=216.58.208.164,
Service Name=N/A,Service Portno=443,Lrecl=1,
Recfm=Fixed
NOTE: The file Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-9324-7be0aa8a\contents\SAS Temporary
Files\_TD6628_ROSSI_\#LN00036,
RECFM=F,LRECL=1,Dimensione (byte)=0,
Ultima modifica=29 gennaio 2020 14:22:23,
Create Time=29 gennaio 2020 14:22:23
5 The SAS System 14:16 Wednesday, January 29, 2020
NOTE: 236 records were read from the infile X.
NOTE: 236 records were written to the file Z.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.27 seconds
cpu time 0.04 seconds
NOTE: The infile Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-9324-7be0aa8a\contents\SAS Temporary
Files\_TD6628_ROSSI_\#LN00036,
RECFM=F,LRECL=236,Dimensione (byte)=236,
Ultima modifica=29 gennaio 2020 14:22:23,
Create Time=29 gennaio 2020 14:22:23
NOTE: 1 record was read from the infile Z.
NOTE: SAS went to a new line when INPUT @'CHARACTER_STRING' scanned past the end of a line.
NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Fileref X has been deassigned.
NOTE: Fileref Z has been deassigned.
NOTE: Appending WORK.TEMP a WORK.DISTANCE_TIME.
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: 1 observations added.
NOTE: The data set WORK.DISTANCE_TIME has 2 observations and 2 variables.
NOTE: PROCEDURE APPEND ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
NOTE: The infile X is:
Filename=https://www.google.com/maps/api/directions/json?origin=42.691560,-73.827840&destination=36.896936,-9...
uS_QMZlitN9RwRhRT7IbaT4vq8T5P0=AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0,
Local Host Name=Rossi,
Local Host IP addr=fe80::10d0:1421:f87:de32%13,
Service Hostname Name=lhr25s09-in-f164.1e100.net,
Service IP addr=216.58.208.164,
Service Name=N/A,Service Portno=443,Lrecl=1,
Recfm=Fixed
6 The SAS System 14:16 Wednesday, January 29, 2020
NOTE: The file Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-9324-7be0aa8a\contents\SAS Temporary
Files\_TD6628_ROSSI_\#LN00037,
RECFM=F,LRECL=1,Dimensione (byte)=0,
Ultima modifica=29 gennaio 2020 14:22:23,
Create Time=29 gennaio 2020 14:22:23
NOTE: 236 records were read from the infile X.
NOTE: 236 records were written to the file Z.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.29 seconds
cpu time 0.01 seconds
NOTE: The infile Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-9324-7be0aa8a\contents\SAS Temporary
Files\_TD6628_ROSSI_\#LN00037,
RECFM=F,LRECL=236,Dimensione (byte)=236,
Ultima modifica=29 gennaio 2020 14:22:23,
Create Time=29 gennaio 2020 14:22:23
NOTE: 1 record was read from the infile Z.
NOTE: SAS went to a new line when INPUT @'CHARACTER_STRING' scanned past the end of a line.
NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Fileref X has been deassigned.
NOTE: Fileref Z has been deassigned.
NOTE: Appending WORK.TEMP a WORK.DISTANCE_TIME.
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: 1 observations added.
NOTE: The data set WORK.DISTANCE_TIME has 3 observations and 2 variables.
NOTE: PROCEDURE APPEND ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
NOTE: The infile X is:
Filename=https://www.google.com/maps/api/directions/json?origin=42.691560,-73.827840&destination=34.14464,-11...
uS_QMZlitN9RwRhRT7IbaT4vq8T5P0=AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0,
7 The SAS System 14:16 Wednesday, January 29, 2020
Local Host Name=Rossi,
Local Host IP addr=fe80::10d0:1421:f87:de32%13,
Service Hostname Name=lhr25s09-in-f164.1e100.net,
Service IP addr=216.58.208.164,
Service Name=N/A,Service Portno=443,Lrecl=1,
Recfm=Fixed
NOTE: The file Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-9324-7be0aa8a\contents\SAS Temporary
Files\_TD6628_ROSSI_\#LN00038,
RECFM=F,LRECL=1,Dimensione (byte)=0,
Ultima modifica=29 gennaio 2020 14:22:24,
Create Time=29 gennaio 2020 14:22:24
NOTE: 236 records were read from the infile X.
NOTE: 236 records were written to the file Z.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.39 seconds
cpu time 0.04 seconds
NOTE: The infile Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-9324-7be0aa8a\contents\SAS Temporary
Files\_TD6628_ROSSI_\#LN00038,
RECFM=F,LRECL=236,Dimensione (byte)=236,
Ultima modifica=29 gennaio 2020 14:22:24,
Create Time=29 gennaio 2020 14:22:24
NOTE: 1 record was read from the infile Z.
NOTE: SAS went to a new line when INPUT @'CHARACTER_STRING' scanned past the end of a line.
NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.01 seconds
cpu time 0.00 seconds
NOTE: Fileref X has been deassigned.
NOTE: Fileref Z has been deassigned.
NOTE: Appending WORK.TEMP a WORK.DISTANCE_TIME.
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: 1 observations added.
NOTE: The data set WORK.DISTANCE_TIME has 4 observations and 2 variables.
NOTE: PROCEDURE APPEND ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.01 seconds
WARNING: Apparent symbolic reference DESTINATION not resolved.
8 The SAS System 14:16 Wednesday, January 29, 2020
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
NOTE: The infile X is:
Filename=https://www.google.com/maps/api/directions/json?origin=42.691560,-73.827840&destination=40.212752,-1...
nuS_QMZlitN9RwRhRT7IbaT4vq8T5P0=AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0,
Local Host Name=Rossi,
Local Host IP addr=fe80::10d0:1421:f87:de32%13,
Service Hostname Name=lhr25s09-in-f164.1e100.net,
Service IP addr=216.58.208.164,
Service Name=N/A,Service Portno=443,Lrecl=1,
Recfm=Fixed
NOTE: The file Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-9324-7be0aa8a\contents\SAS Temporary
Files\_TD6628_ROSSI_\#LN00039,
RECFM=F,LRECL=1,Dimensione (byte)=0,
Ultima modifica=29 gennaio 2020 14:22:24,
Create Time=29 gennaio 2020 14:22:24
NOTE: 236 records were read from the infile X.
NOTE: 236 records were written to the file Z.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.29 seconds
cpu time 0.00 seconds
NOTE: The infile Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-9324-7be0aa8a\contents\SAS Temporary
Files\_TD6628_ROSSI_\#LN00039,
RECFM=F,LRECL=236,Dimensione (byte)=236,
Ultima modifica=29 gennaio 2020 14:22:24,
Create Time=29 gennaio 2020 14:22:24
NOTE: 1 record was read from the infile Z.
NOTE: SAS went to a new line when INPUT @'CHARACTER_STRING' scanned past the end of a line.
NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Fileref X has been deassigned.
NOTE: Fileref Z has been deassigned.
NOTE: Appending WORK.TEMP a WORK.DISTANCE_TIME.
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: 1 observations added.
NOTE: The data set WORK.DISTANCE_TIME has 5 observations and 2 variables.
NOTE: PROCEDURE APPEND ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.01 seconds
9 The SAS System 14:16 Wednesday, January 29, 2020
117
118 *
119 add variables from original data set to new data set distance_time
120 use geodist function to calculate straight line distance
121 ;
122 data distance_time;
123 set distance_time;
124 set lat_long point=_n_;
125 straight_line = round(geodist(&ll1,-73.827840,y,x,'DM'), 0.01);
_______
72
ERROR 72-185: The GEODIST function call has too many arguments.
126 run;
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
125:49
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.DISTANCE_TIME may be incomplete. When this step was stopped there were 0 observations and 8 variables.
WARNING: Data set WORK.DISTANCE_TIME was not replaced because il passo è stato interrotto.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
127
128 proc print data=distance_time noobs label;
129 var x y time distance straight_line zip city statecode;
ERROR: Variable X not found.
ERROR: Variable Y not found.
ERROR: Variable STRAIGHT_LINE not found.
ERROR: Variable ZIP not found.
ERROR: Variable CITY not found.
ERROR: Variable STATECODE not found.
130 format zip z5. time time6. ;
131 run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
132
133
134
135 %LET _CLIENTTASKLABEL=;
136 %LET _CLIENTPROCESSFLOWNAME=;
137 %LET _CLIENTPROJECTPATH=;
138 %LET _CLIENTPROJECTPATHHOST=;
139 %LET _CLIENTPROJECTNAME=;
140 %LET _SASPROGRAMFILE=;
141 %LET _SASPROGRAMFILEHOST=;
142
143 ;*';*";*/;quit;run;
144 ODS _ALL_ CLOSE;
145
146
147 QUIT; RUN;
10 The SAS System 14:16 Wednesday, January 29, 2020
148
When you try to call gedodist() like this;
straight_line = round(geodist(&ll1,-73.827840,y,x,'DM'), 0.01);
after resolving &ll1, which contains
42.691560,-73.827840
you get this:
straight_line = round(geodist(42.691560,-73.827840,-73.827840,y,x,'DM'), 0.01);
and therefore supply 6 arguments to geodist(), but this function accepts a maximum of only 5.
I guess you wanted this:
straight_line = round(geodist(&ll1,y,x,'DM'), 0.01);
as ,-73.827840 is already contained in &ll1. I ran your code with this change and it seemed to work.
thank you for the correction,
but the "distance_time" table continues to have missing in "distance" and "time" variables.
this is the log
1 The SAS System 16:03 Wednesday, January 29, 2020
1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='3_Distanza_tempo.sas';
4 %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project';
5 %LET _CLIENTPROJECTPATH='';
6 %LET _CLIENTPROJECTPATHHOST='';
7 %LET _CLIENTPROJECTNAME='';
8 %LET _SASPROGRAMFILE='X:\ISTAT\LINEE_DI_ATTIVITA_2019\Aree interne\prg\distanza\3_Distanza_tempo.sas';
9 %LET _SASPROGRAMFILEHOST='ROSSI';
10
11 ODS _ALL_ CLOSE;
12 OPTIONS DEV=SVG;
13 GOPTIONS XPIXELS=0 YPIXELS=0;
14 %macro HTML5AccessibleGraphSupported;
15 %if %_SAS_VERCOMP(9, 4, 4) >= 0 %then ACCESSIBLE_GRAPH;
16 %mend;
17 FILENAME EGHTML TEMP;
18 ODS HTML5(ID=EGHTML) FILE=EGHTML
19 OPTIONS(BITMAP_MODE='INLINE')
20 %HTML5AccessibleGraphSupported
21 ENCODING='utf-8'
22 STYLE=HtmlBlue
23 NOGTITLE
24 NOGFOOTNOTE
25 GPATH=&sasworklocation
26 ;
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
27
28 %let ll1=%str(42.691560,-73.827840);
29 %let key = AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0;
30
31 *
32 create a data set with locations specified in latitude and longitude
33 a random sample of 5 observations from SASHELP.ZIPCODE
34 use SEED=0 to get a new sample each time program is run
35 ;
36
37 proc surveyselect data=sashelp.zipcode (keep=zip city statecode x y)
38 out=lat_long sampsize=5 seed=0;
39 run;
NOTE: The data set WORK.LAT_LONG has 5 observations and 5 variables.
NOTE: PROCEDURE SURVEYSELECT ha utilizzato (tempo totale di elaborazione):
real time 0.08 seconds
cpu time 0.07 seconds
40
41 *
42 place number of zip in a macro variable
43 in this example you know it is 5
44 but you might not know in another use of the SAS code
45 ;
46 data _null_;
47 call symputx('nlls',obs);
48 stop;
49 set lat_long nobs=obs;
50 run;
2 The SAS System 16:03 Wednesday, January 29, 2020
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
51
52 * create a macro that contains a loop to access Google Maps multiple time;
53 %macro distance_time;
54
55 * delete any data set named DISTANCE_TIME that might exist in the WORK library;
56 proc datasets lib=work nolist;
57 delete distance_time;
58 quit;
59
60 %do j=1 %to &nlls;
61 data _null_;
62 nrec = &j;
63 set lat_long point=nrec;
64 call symputx('ll2',catx(',',y,x));
65 stop;
66 run;
67
68 * lat/long of centroid of zip 12203 hard-coded as part of the URL;
69 filename x url "https://www.google.com/maps/api/directions/json?origin=&ll1&destination=&ll2&key=&Key";
70 filename z temp;
71
72 * same technique used in the example with a pair of lat/long coodinates;
73 data _null_;
74 infile x recfm=f lrecl=1 end=eof;
75 file z recfm=f lrecl=1;
76 input @1 x $char1.;
77 put @1 x $char1.;
78 if eof;
79 call symputx('filesize',_n_);
80 run;
81
82 * drive time as a numeric variable;
83 data temp;
84 infile z recfm=f lrecl=&filesize. eof=done;
85 input @ 'miles' +(-15) @ '"' distance :comma12. text $30.;
86 units = scan(text,1,'"');
87 text = scan(text,3,'"');
88 * convert times to seconds;
89 select;
90 * combine days and hours;
91 when (find(text,'d') ne 0) time = sum(86400*input(scan(text,1,' '),best.),
92 3600*input(scan(text,3,' '),best.));
93 * combine hours and minutes;
94 when (find(text,'h') ne 0) time = sum(3600*input(scan(text,1,' '),best.),
95 60*input(scan(text,3,' '),best.));
96 * just minutes;
97 otherwise time = 60*input(scan(text,1,' '),best.);
98 end;
99 output;
100 keep distance time;
101 stop;
102 done:
3 The SAS System 16:03 Wednesday, January 29, 2020
103 output;
104 run;
105
106 filename x clear;
107 filename z clear;
108
109 * add an observation to the data set DISTANCE_TIME;
110 proc append base=distance_time data=temp;
111 run;
112 %end;
113 %mend;
114
115 * use the macro;
116 %distance_time;
NOTE: Deleting WORK.DISTANCE_TIME (memtype=DATA).
NOTE: PROCEDURE DATASETS ha utilizzato (tempo totale di elaborazione):
real time 0.06 seconds
cpu time 0.00 seconds
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
NOTE: The infile X is:
Filename=https://www.google.com/maps/api/directions/json?origin=42.691560,-73.827840&destination=43.23876,-71...
MZlitN9RwRhRT7IbaT4vq8T5P0=AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0,
Local Host Name=Rossi,
Local Host IP addr=fe80::10d0:1421:f87:de32%13,
Service Hostname Name=mil07s08-in-f4.1e100.net,
Service IP addr=216.58.206.68,Service Name=N/A,
Service Portno=443,Lrecl=1,Recfm=Fixed
NOTE: The file Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-5328-899b9f2a\contents\SAS Temporary
Files\_TD9692_ROSSI_\#LN00050,
RECFM=F,LRECL=1,Dimensione (byte)=0,
Ultima modifica=29 gennaio 2020 16:09:41,
Create Time=29 gennaio 2020 16:09:41
NOTE: 236 records were read from the infile X.
NOTE: 236 records were written to the file Z.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.17 seconds
cpu time 0.00 seconds
NOTE: The infile Z is:
4 The SAS System 16:03 Wednesday, January 29, 2020
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-5328-899b9f2a\contents\SAS Temporary
Files\_TD9692_ROSSI_\#LN00050,
RECFM=F,LRECL=236,Dimensione (byte)=236,
Ultima modifica=29 gennaio 2020 16:09:41,
Create Time=29 gennaio 2020 16:09:41
NOTE: 1 record was read from the infile Z.
NOTE: SAS went to a new line when INPUT @'CHARACTER_STRING' scanned past the end of a line.
NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Fileref X has been deassigned.
NOTE: Fileref Z has been deassigned.
NOTE: Appending WORK.TEMP a WORK.DISTANCE_TIME.
NOTE: BASE data set does not exist. DATA file is being copied to BASE file.
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: The data set WORK.DISTANCE_TIME has 1 observations and 2 variables.
NOTE: PROCEDURE APPEND ha utilizzato (tempo totale di elaborazione):
real time 0.03 seconds
cpu time 0.03 seconds
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
NOTE: The infile X is:
Filename=https://www.google.com/maps/api/directions/json?origin=42.691560,-73.827840&destination=40.580308,-7...
uS_QMZlitN9RwRhRT7IbaT4vq8T5P0=AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0,
Local Host Name=Rossi,
Local Host IP addr=fe80::10d0:1421:f87:de32%13,
Service Hostname Name=mil07s08-in-f4.1e100.net,
Service IP addr=216.58.206.68,Service Name=N/A,
Service Portno=443,Lrecl=1,Recfm=Fixed
NOTE: The file Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-5328-899b9f2a\contents\SAS Temporary
Files\_TD9692_ROSSI_\#LN00051,
RECFM=F,LRECL=1,Dimensione (byte)=0,
Ultima modifica=29 gennaio 2020 16:09:41,
Create Time=29 gennaio 2020 16:09:41
NOTE: 236 records were read from the infile X.
NOTE: 236 records were written to the file Z.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
5 The SAS System 16:03 Wednesday, January 29, 2020
real time 0.14 seconds
cpu time 0.04 seconds
NOTE: The infile Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-5328-899b9f2a\contents\SAS Temporary
Files\_TD9692_ROSSI_\#LN00051,
RECFM=F,LRECL=236,Dimensione (byte)=236,
Ultima modifica=29 gennaio 2020 16:09:41,
Create Time=29 gennaio 2020 16:09:41
NOTE: 1 record was read from the infile Z.
NOTE: SAS went to a new line when INPUT @'CHARACTER_STRING' scanned past the end of a line.
NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.01 seconds
NOTE: Fileref X has been deassigned.
NOTE: Fileref Z has been deassigned.
NOTE: Appending WORK.TEMP a WORK.DISTANCE_TIME.
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: 1 observations added.
NOTE: The data set WORK.DISTANCE_TIME has 2 observations and 2 variables.
NOTE: PROCEDURE APPEND ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.01 seconds
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
NOTE: The infile X is:
Filename=https://www.google.com/maps/api/directions/json?origin=42.691560,-73.827840&destination=38.362467,-7...
uS_QMZlitN9RwRhRT7IbaT4vq8T5P0=AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0,
Local Host Name=Rossi,
Local Host IP addr=fe80::10d0:1421:f87:de32%13,
Service Hostname Name=mil07s08-in-f4.1e100.net,
Service IP addr=216.58.206.68,Service Name=N/A,
Service Portno=443,Lrecl=1,Recfm=Fixed
NOTE: The file Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-5328-899b9f2a\contents\SAS Temporary
Files\_TD9692_ROSSI_\#LN00052,
RECFM=F,LRECL=1,Dimensione (byte)=0,
6 The SAS System 16:03 Wednesday, January 29, 2020
Ultima modifica=29 gennaio 2020 16:09:41,
Create Time=29 gennaio 2020 16:09:41
NOTE: 236 records were read from the infile X.
NOTE: 236 records were written to the file Z.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.14 seconds
cpu time 0.00 seconds
NOTE: The infile Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-5328-899b9f2a\contents\SAS Temporary
Files\_TD9692_ROSSI_\#LN00052,
RECFM=F,LRECL=236,Dimensione (byte)=236,
Ultima modifica=29 gennaio 2020 16:09:41,
Create Time=29 gennaio 2020 16:09:41
NOTE: 1 record was read from the infile Z.
NOTE: SAS went to a new line when INPUT @'CHARACTER_STRING' scanned past the end of a line.
NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Fileref X has been deassigned.
NOTE: Fileref Z has been deassigned.
NOTE: Appending WORK.TEMP a WORK.DISTANCE_TIME.
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: 1 observations added.
NOTE: The data set WORK.DISTANCE_TIME has 3 observations and 2 variables.
NOTE: PROCEDURE APPEND ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
NOTE: The infile X is:
Filename=https://www.google.com/maps/api/directions/json?origin=42.691560,-73.827840&destination=32.840314,-8...
uS_QMZlitN9RwRhRT7IbaT4vq8T5P0=AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0,
Local Host Name=Rossi,
Local Host IP addr=fe80::10d0:1421:f87:de32%13,
Service Hostname Name=mil07s08-in-f4.1e100.net,
Service IP addr=216.58.206.68,Service Name=N/A,
Service Portno=443,Lrecl=1,Recfm=Fixed
7 The SAS System 16:03 Wednesday, January 29, 2020
NOTE: The file Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-5328-899b9f2a\contents\SAS Temporary
Files\_TD9692_ROSSI_\#LN00053,
RECFM=F,LRECL=1,Dimensione (byte)=0,
Ultima modifica=29 gennaio 2020 16:09:42,
Create Time=29 gennaio 2020 16:09:42
NOTE: 236 records were read from the infile X.
NOTE: 236 records were written to the file Z.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.15 seconds
cpu time 0.01 seconds
NOTE: The infile Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-5328-899b9f2a\contents\SAS Temporary
Files\_TD9692_ROSSI_\#LN00053,
RECFM=F,LRECL=236,Dimensione (byte)=236,
Ultima modifica=29 gennaio 2020 16:09:42,
Create Time=29 gennaio 2020 16:09:42
NOTE: 1 record was read from the infile Z.
NOTE: SAS went to a new line when INPUT @'CHARACTER_STRING' scanned past the end of a line.
NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Fileref X has been deassigned.
NOTE: Fileref Z has been deassigned.
NOTE: Appending WORK.TEMP a WORK.DISTANCE_TIME.
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: 1 observations added.
NOTE: The data set WORK.DISTANCE_TIME has 4 observations and 2 variables.
NOTE: PROCEDURE APPEND ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.01 seconds
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
WARNING: Apparent symbolic reference DESTINATION not resolved.
NOTE: The infile X is:
Filename=https://www.google.com/maps/api/directions/json?origin=42.691560,-73.827840&destination=33.919916,-1...
8 The SAS System 16:03 Wednesday, January 29, 2020
nuS_QMZlitN9RwRhRT7IbaT4vq8T5P0=AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0,
Local Host Name=Rossi,
Local Host IP addr=fe80::10d0:1421:f87:de32%13,
Service Hostname Name=mil07s08-in-f4.1e100.net,
Service IP addr=216.58.206.68,Service Name=N/A,
Service Portno=443,Lrecl=1,Recfm=Fixed
NOTE: The file Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-5328-899b9f2a\contents\SAS Temporary
Files\_TD9692_ROSSI_\#LN00054,
RECFM=F,LRECL=1,Dimensione (byte)=0,
Ultima modifica=29 gennaio 2020 16:09:42,
Create Time=29 gennaio 2020 16:09:42
NOTE: 236 records were read from the infile X.
NOTE: 236 records were written to the file Z.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.14 seconds
cpu time 0.01 seconds
NOTE: The infile Z is:
Nome file=C:\Users\A.Rossi\AppData\Roaming\SAS\EnterpriseGuide\EGTEMP\SEG-5328-899b9f2a\contents\SAS Temporary
Files\_TD9692_ROSSI_\#LN00054,
RECFM=F,LRECL=236,Dimensione (byte)=236,
Ultima modifica=29 gennaio 2020 16:09:42,
Create Time=29 gennaio 2020 16:09:42
NOTE: 1 record was read from the infile Z.
NOTE: SAS went to a new line when INPUT @'CHARACTER_STRING' scanned past the end of a line.
NOTE: The data set WORK.TEMP has 1 observations and 2 variables.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Fileref X has been deassigned.
NOTE: Fileref Z has been deassigned.
NOTE: Appending WORK.TEMP a WORK.DISTANCE_TIME.
NOTE: There were 1 observations read from the data set WORK.TEMP.
NOTE: 1 observations added.
NOTE: The data set WORK.DISTANCE_TIME has 5 observations and 2 variables.
NOTE: PROCEDURE APPEND ha utilizzato (tempo totale di elaborazione):
real time 0.00 seconds
cpu time 0.00 seconds
117
118 *
119 add variables from original data set to new data set distance_time
120 use geodist function to calculate straight line distance
121 ;
122 data distance_time;
123 set distance_time;
9 The SAS System 16:03 Wednesday, January 29, 2020
124 set lat_long point=_n_;
125 straight_line = round(geodist(&ll1,y,x,'DM'), 0.01);
126 run;
NOTE: There were 5 observations read from the data set WORK.DISTANCE_TIME.
NOTE: The data set WORK.DISTANCE_TIME has 5 observations and 8 variables.
NOTE: DATA statement ha utilizzato (tempo totale di elaborazione):
real time 0.01 seconds
cpu time 0.01 seconds
127
128 proc print data=distance_time noobs label;
129 var x y time distance straight_line zip city statecode;
130 format zip z5. time time6. ;
131 run;
NOTE: There were 5 observations read from the data set WORK.DISTANCE_TIME.
NOTE: PROCEDURE PRINT ha utilizzato (tempo totale di elaborazione):
real time 0.03 seconds
cpu time 0.03 seconds
132
133 %LET _CLIENTTASKLABEL=;
134 %LET _CLIENTPROCESSFLOWNAME=;
135 %LET _CLIENTPROJECTPATH=;
136 %LET _CLIENTPROJECTPATHHOST=;
137 %LET _CLIENTPROJECTNAME=;
138 %LET _SASPROGRAMFILE=;
139 %LET _SASPROGRAMFILEHOST=;
140
141 ;*';*";*/;quit;run;
142 ODS _ALL_ CLOSE;
143
144
145 QUIT; RUN;
146
First of all, your URL is not built correctly. You need to mask parts that are not macro variables:
filename x url "https://www.google.com/maps/api/directions/json?origin=&ll1%nrstr(&destination=)&ll2%nrstr(&key=)&Key";
But then, when I use your (correctly built) URL:
https://www.google.com/maps/api/directions/json?origin=42.691560,-73.827840&destination=30.213433,-92.373777&key=AIzaSyAhnuS_QMZlitN9RwRhRT7IbaT4vq8T5P0
, I get this response:
{ "error_message" : "This API project is not authorized to use this API.", "routes" : [], "status" : "REQUEST_DENIED" }
so it might be your key that is wrong.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.