<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Driving Distance and Time between residential addresses and health clinics using Google Maps in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916592#M361002</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I am encountering difficulties in calculating the driving distance and time between residential addresses and health clinics using SAS and Google Maps. I have two separate datasets: one contains the lat and long coordinates of residential addresses, and the other contains the lat and long coordinates for health clinics. These datasets do not have a unique identifier to link all records together.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My goal is to compute the median distance and time between each residential address and its nearest health clinic. I reviewed similar request for help, but I have been unsuccessful. Two methods I tried were not recognized by SAS. I've provided the syntax for both of my attempts here. Any guidance or alternative approaches would be greatly appreciated!&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*ATTEMPT 1*/
data Res_addrs; 
	set Res_addrs;
	addr1 = catx(',',y,x); 
run;
data clinic_addr; 
	set clinic_addr;
	addr2 = catx(',',y,x); 
	rename USER_lastname = ClinicID;
run;

data AddressFile;
	set Res_addrs clinic_addr;
run;


*Keep ID and coordinates only;
data Addresses;
	set AddressFile;
	keep patientid ClinicID addr1 addr2;
run;

*Check;
proc contents data=Addresses;
run;


*Macro to connect Google Maps; 
data _null_;
call symputx('Observations',obs);
stop;
set Addresses nobs=obs;
run;
 

/** SAS doesn't seem to recognized below **/

%macro distance_time;
 
%do j=1 %to 5 /*&amp;amp;Observations*/;
data _null_;
nrec = &amp;amp;j;
set Addresses point=nrec;
%let ll1=addr1;
%let ll2=addr2;
stop;
run;
 
filename x url "https://www.google.com/maps/dir/&amp;amp;ll1/&amp;amp;ll2/?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;

*Drive distance &amp;amp; time;
data temp;
infile z recfm=f lrecl=&amp;amp;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 obs to the data set;
proc append base=distance_time data=temp;
run;
%end;
%mend;
 
*Run the macro;
%distance_time;
 
*Add vars from original dataset to distance_time;
data distance_time;
set distance_time;
set Addresses point=_n_;
straight_line = round(geodist(&amp;amp;ll1/&amp;amp;ll2,'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;


/******************************/

/* ATTEMPT 2 */

*Rename;
data Res_addrs; 
	set Res_addrs;
	rename  y = PatientLatitude
			x = PatientLongitude ; 
run;
data clinic_addr; 
	set clinic_addr;
	rename  y = ClinicLatitude
			x = ClinicLongitude
			USER_lastname = ClinicID ;
run;


/** SAS doesn't seem to recognize below **/

*Step 1 - Macro;
%macro distance
  (patientID=
  ,patientLatitude=
  ,patientLongitude=
  ,clinicID=
  ,clinicLatitude=
  ,clinicLongitude=
  ,out= mapmacro ) ;

filename x url "https://www.google.com/maps/dir/?api=1&amp;amp;origin=&amp;amp;patientLatitude.,&amp;amp;patientLongitude.&amp;amp;destination=&amp;amp;clinicLatitude.,&amp;amp;clinicLongitude.&amp;amp;travelmode=driving";
filename z temp;

%local filesize ;
 
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;


*Step 2 - Driving distance ;
data __distance(keep=PatientID ClinicID Distance PatientLatitude PatientLongitude ClinicLatitude ClinicLongitude) ;
  length PatientID $8 ClinicID $8 PatientLatitude PatientLongitude ClinicLatitude ClinicLongitude $20;
  PatientID="&amp;amp;PatientID" ;
  ClinicID="&amp;amp;ClinicID" ;
  PatientLatitude="&amp;amp;PatientLatitude" ;
  PatientLongitude="&amp;amp;PatientLongitude" ;
  ClinicLatitude="&amp;amp;ClinicLatitude" ;
  ClinicLongitude="&amp;amp;ClinicLongitude" ;

  infile z recfm=f lrecl=&amp;amp;filesize. eof=done;
  input @ 'miles' +(-15) @ '"' Distance :comma12. text $30.;
  units    = scan(text,1,'"');
  text     = scan(text,3,'"');
  output; 

  put PatientID= ClinicID= Distance=;
  stop;
  done:
  output;
run;

proc append base=&amp;amp;out data=__distance ;
run ;

proc delete data=__distance ;
run ;

filename x clear ;
filename z clear ;

%mend distance ;


*Step 3 - all driving routes;
proc sql ;
  create table routes as
  select 
    ehdi_rucc3.ID as PatientID
   ,ehdi_rucc3.Latitude as PatientLatitude
   ,ehdi_rucc3.Longitude as PatientLongitude
   ,Aud_Clinic1.ID as ClinicID
   ,Aud_Clinic1.Latitude as ClinicLatitude
   ,Aud_Clinic1.Longitude as ClinicLongitude
  from ehdi_rucc3,Aud_Clinic1
 ;
quit ;


*Step 4 - run macro;
data _null_;
  set routes;
  call execute 
    (
    '%nrstr('
        ||  '%distance'
        ||    '('
        ||    ' patientID='         || trim(patientID)
        ||    ',patientLatitude='   || trim(patientLatitude)
        ||    ',patientLongitude='  || trim(patientLongitude)
        ||    ',ClinicID='        || trim(ClinicID)
        ||    ',ClinicLatitude='  || trim(ClinicLatitude)
        ||    ',ClinicLongitude=' || trim(ClinicLongitude)
        ||    ',out=mydistances'
        ||    ' )'
        || ')'          
    );
run;
&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;I also attached a copy of the log for reference.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2024 23:09:54 GMT</pubDate>
    <dc:creator>ark123</dc:creator>
    <dc:date>2024-02-16T23:09:54Z</dc:date>
    <item>
      <title>Driving Distance and Time between residential addresses and health clinics using Google Maps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916592#M361002</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I am encountering difficulties in calculating the driving distance and time between residential addresses and health clinics using SAS and Google Maps. I have two separate datasets: one contains the lat and long coordinates of residential addresses, and the other contains the lat and long coordinates for health clinics. These datasets do not have a unique identifier to link all records together.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My goal is to compute the median distance and time between each residential address and its nearest health clinic. I reviewed similar request for help, but I have been unsuccessful. Two methods I tried were not recognized by SAS. I've provided the syntax for both of my attempts here. Any guidance or alternative approaches would be greatly appreciated!&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*ATTEMPT 1*/
data Res_addrs; 
	set Res_addrs;
	addr1 = catx(',',y,x); 
run;
data clinic_addr; 
	set clinic_addr;
	addr2 = catx(',',y,x); 
	rename USER_lastname = ClinicID;
run;

data AddressFile;
	set Res_addrs clinic_addr;
run;


*Keep ID and coordinates only;
data Addresses;
	set AddressFile;
	keep patientid ClinicID addr1 addr2;
run;

*Check;
proc contents data=Addresses;
run;


*Macro to connect Google Maps; 
data _null_;
call symputx('Observations',obs);
stop;
set Addresses nobs=obs;
run;
 

/** SAS doesn't seem to recognized below **/

%macro distance_time;
 
%do j=1 %to 5 /*&amp;amp;Observations*/;
data _null_;
nrec = &amp;amp;j;
set Addresses point=nrec;
%let ll1=addr1;
%let ll2=addr2;
stop;
run;
 
filename x url "https://www.google.com/maps/dir/&amp;amp;ll1/&amp;amp;ll2/?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;

*Drive distance &amp;amp; time;
data temp;
infile z recfm=f lrecl=&amp;amp;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 obs to the data set;
proc append base=distance_time data=temp;
run;
%end;
%mend;
 
*Run the macro;
%distance_time;
 
*Add vars from original dataset to distance_time;
data distance_time;
set distance_time;
set Addresses point=_n_;
straight_line = round(geodist(&amp;amp;ll1/&amp;amp;ll2,'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;


/******************************/

/* ATTEMPT 2 */

*Rename;
data Res_addrs; 
	set Res_addrs;
	rename  y = PatientLatitude
			x = PatientLongitude ; 
run;
data clinic_addr; 
	set clinic_addr;
	rename  y = ClinicLatitude
			x = ClinicLongitude
			USER_lastname = ClinicID ;
run;


/** SAS doesn't seem to recognize below **/

*Step 1 - Macro;
%macro distance
  (patientID=
  ,patientLatitude=
  ,patientLongitude=
  ,clinicID=
  ,clinicLatitude=
  ,clinicLongitude=
  ,out= mapmacro ) ;

filename x url "https://www.google.com/maps/dir/?api=1&amp;amp;origin=&amp;amp;patientLatitude.,&amp;amp;patientLongitude.&amp;amp;destination=&amp;amp;clinicLatitude.,&amp;amp;clinicLongitude.&amp;amp;travelmode=driving";
filename z temp;

%local filesize ;
 
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;


*Step 2 - Driving distance ;
data __distance(keep=PatientID ClinicID Distance PatientLatitude PatientLongitude ClinicLatitude ClinicLongitude) ;
  length PatientID $8 ClinicID $8 PatientLatitude PatientLongitude ClinicLatitude ClinicLongitude $20;
  PatientID="&amp;amp;PatientID" ;
  ClinicID="&amp;amp;ClinicID" ;
  PatientLatitude="&amp;amp;PatientLatitude" ;
  PatientLongitude="&amp;amp;PatientLongitude" ;
  ClinicLatitude="&amp;amp;ClinicLatitude" ;
  ClinicLongitude="&amp;amp;ClinicLongitude" ;

  infile z recfm=f lrecl=&amp;amp;filesize. eof=done;
  input @ 'miles' +(-15) @ '"' Distance :comma12. text $30.;
  units    = scan(text,1,'"');
  text     = scan(text,3,'"');
  output; 

  put PatientID= ClinicID= Distance=;
  stop;
  done:
  output;
run;

proc append base=&amp;amp;out data=__distance ;
run ;

proc delete data=__distance ;
run ;

filename x clear ;
filename z clear ;

%mend distance ;


*Step 3 - all driving routes;
proc sql ;
  create table routes as
  select 
    ehdi_rucc3.ID as PatientID
   ,ehdi_rucc3.Latitude as PatientLatitude
   ,ehdi_rucc3.Longitude as PatientLongitude
   ,Aud_Clinic1.ID as ClinicID
   ,Aud_Clinic1.Latitude as ClinicLatitude
   ,Aud_Clinic1.Longitude as ClinicLongitude
  from ehdi_rucc3,Aud_Clinic1
 ;
quit ;


*Step 4 - run macro;
data _null_;
  set routes;
  call execute 
    (
    '%nrstr('
        ||  '%distance'
        ||    '('
        ||    ' patientID='         || trim(patientID)
        ||    ',patientLatitude='   || trim(patientLatitude)
        ||    ',patientLongitude='  || trim(patientLongitude)
        ||    ',ClinicID='        || trim(ClinicID)
        ||    ',ClinicLatitude='  || trim(ClinicLatitude)
        ||    ',ClinicLongitude=' || trim(ClinicLongitude)
        ||    ',out=mydistances'
        ||    ' )'
        || ')'          
    );
run;
&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;I also attached a copy of the log for reference.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 23:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916592#M361002</guid>
      <dc:creator>ark123</dc:creator>
      <dc:date>2024-02-16T23:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Driving Distance and Time between residential addresses and health clinics using Google Maps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916596#M361004</link>
      <description>&lt;P&gt;If this is supposed to assign values to a macro variable using the value of a variable in a data set it is wrong.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%do j=1 %to 5 /*&amp;amp;Observations*/;
data _null_;
nrec = &amp;amp;j;
set Addresses point=nrec;
%let ll1=addr1;
%let ll2=addr2;
stop;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp; The timing of execution of macro statements and the data step means that the %let executes in the compile phase of the data step.&amp;nbsp; So LL1 has the text value of addr1, not that of the variable.&lt;/P&gt;
&lt;P&gt;Use CALL SYMPUTX to assign a value to macro variable in a data step.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%do j=1 %to 5 /*&amp;amp;Observations*/;
data _null_;
nrec = &amp;amp;j;
set Addresses point=nrec;
call symputx('ll1')= addr1; /* best is to actually use a PUT with format if the value is numeric to control the conversion to text that the macro variable with hold*/
Call symputx('ll2')=addr2;
stop;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your call to GEODIST is likely quite suspect as well&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;straight_line = round(geodist(&amp;amp;ll1/&amp;amp;ll2,'DM'), 0.01);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The Geodist function takes 4 numeric parameters of lat and long for start and end point. I don't see any way that "&amp;amp;ll1" id going to work even when defined properly and / is entirely too likely be interpreted as a division between two numeric values. Meaning that you are short 3 parameters.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 23:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916596#M361004</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-02-16T23:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Driving Distance and Time between residential addresses and health clinics using Google Maps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916635#M361023</link>
      <description>&lt;P&gt;Can you be more specific about what parts of that are not working?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have a list of the pairs of FROM/TO locations you want to find the distances between?&amp;nbsp; Note this does not need to include all patients or all clinics.&amp;nbsp; Just all patient LOCATIONS and all clinic LOCATIONS.&amp;nbsp; Some patients might share a location. Some clinics might share a location.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have a macro that can calculate the distance between a FROM and TO location? Does it take in just one pair of FROM and TO locations?&amp;nbsp; If so does in aggregate the results into a common dataset?&amp;nbsp; Or does it take in a dataset that has multiple FROM/TO location pairs?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide a pair of LAT/LONG values that you are trying to find the distance between?&amp;nbsp; Can you show working code that calculates the distance for that pair (without any macro variable or macro logic)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So assuming you have successfully created a dataset with all FROM/TO pairs you can use a step like this to generate one macro call for each pair.&amp;nbsp; &amp;nbsp;Let's call the dataset with the FROM/TO locations as PAIRS.&amp;nbsp; And use variable names&amp;nbsp;&amp;nbsp;PatientLatitude,PatientLongitude and&amp;nbsp;ClinicLatitude,ClinicLongitude as the variables with the LAT/LONG pairs.&amp;nbsp; And let's assume you have created a macro named DISTANCE() that takes as input those four values and appends the result to same common dataset.&amp;nbsp; Let's call that dataset DISTANCE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the step to generate the macro calls might look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set pairs;
  call execute(cats('nrstr(%distance)'
    ,'(',PatientLatitude,',',PatientLongitude
    ,',',ClinicLatitude ,',',ClinicLongitude
    ,')'
  ));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Feb 2024 18:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916635#M361023</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-17T18:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Driving Distance and Time between residential addresses and health clinics using Google Maps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916636#M361024</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/430406"&gt;@ark123&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I reviewed similar request for help, but I have been unsuccessful. &amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Have you tried this one? :&lt;BR /&gt;&lt;STRONG&gt;Find driving distance (google maps) using a list of 10 hospital addresses and individual zipcodes&lt;/STRONG&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Find-driving-distance-google-maps-usinga-list-of-10-hospital/td-p/884611" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Find-driving-distance-google-maps-usinga-list-of-10-hospital/td-p/884611&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2024 18:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916636#M361024</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-02-17T18:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: Driving Distance and Time between residential addresses and health clinics using Google Maps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916986#M361199</link>
      <description>The code comes from two other support posts. These were accepted solutions, so they worked for someone., which is why I tried them. But they do not work for me, which is  why I asked for help here.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Find-driving-distance-google-maps-usinga-list-of-10-hospital/m-p/884611" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Find-driving-distance-google-maps-usinga-list-of-10-hospital/m-p/884611&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Find-shortest-distance-between-one-LAT-LONG-and-list-of-other/td-p/593682" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Find-shortest-distance-between-one-LAT-LONG-and-list-of-other/td-p/593682&lt;/A&gt;</description>
      <pubDate>Tue, 20 Feb 2024 15:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916986#M361199</guid>
      <dc:creator>ark123</dc:creator>
      <dc:date>2024-02-20T15:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: Driving Distance and Time between residential addresses and health clinics using Google Maps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916987#M361200</link>
      <description>Yes, I referenced this post. You'll notice the code is same in one of my posted attempts. These are the two support posts I referenced, but they did not work for me or I am missing something. &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Find-driving-distance-google-maps-usinga-list-of-10-hospital/m-p/884611" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Find-driving-distance-google-maps-usinga-list-of-10-hospital/m-p/884611&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Find-shortest-distance-between-one-LAT-LONG-and-list-of-other/td-p/593682" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Find-shortest-distance-between-one-LAT-LONG-and-list-of-other/td-p/593682&lt;/A&gt;</description>
      <pubDate>Tue, 20 Feb 2024 15:31:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916987#M361200</guid>
      <dc:creator>ark123</dc:creator>
      <dc:date>2024-02-20T15:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: Driving Distance and Time between residential addresses and health clinics using Google Maps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916990#M361202</link>
      <description>&lt;P&gt;Hi Tom,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your response. The code will not work because SAS isn't recognizing it correctly (the 'run' statement is black rather than the typical blue). I can select and run, but nothing happens. The issue starts here on 'attempt 1':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;%macro distance_time;
 
%do j=1 %to 5 /*&amp;amp;Observations*/;
data _null_;
nrec = &amp;amp;j;
set Addresses point=nrec;
%let ll1=addr1;
%let ll2=addr2;
stop;
run;
 
filename x url "https://www.google.com/maps/dir/&amp;amp;ll1/&amp;amp;ll2/?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;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code will not work because SAS isn't recognizing it correctly (the 'run' statement is black rather than the typical blue). I can select and run, but nothing happens on 'attempt 2'.&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;%macro distance
  (patientID=
  ,patientLatitude=
  ,patientLongitude=
  ,clinicID=
  ,clinicLatitude=
  ,clinicLongitude=
  ,out= mapmacro ) ;

filename x url "https://www.google.com/maps/dir/?api=1&amp;amp;origin=&amp;amp;patientLatitude.,&amp;amp;patientLongitude.&amp;amp;destination=&amp;amp;clinicLatitude.,&amp;amp;clinicLongitude.&amp;amp;travelmode=driving";
filename z temp;

%local filesize ;
 
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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I should mention that I do not have experience with macros and have never calculated distance using SAS before.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Where I am starting&lt;/STRONG&gt;: I have two datasets. One contains the latitude and longitude of 180,000 residential addresses. The other contains the latitude and longitude of 192 health clinics.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Desired outcome&lt;/STRONG&gt;: I would like to know the distance and travel time between each residential address and its' nearest health clinic.&lt;BR /&gt;(I do not have specific pairs that I am trying to find distances to/from).&lt;/P&gt;
&lt;P&gt;(I have no distances calculated or macro written yet).&lt;/P&gt;
&lt;P&gt;(I don't have any pairs to calculate distances between because I first need to know which health clinic is nearest the residence which would require a distance calculation to be run).&lt;/P&gt;
&lt;P&gt;(I am starting from the beginning with just these two datasets).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps. Let me know if there is anything else&lt;/P&gt;</description>
      <pubDate>Tue, 20 Feb 2024 15:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916990#M361202</guid>
      <dc:creator>ark123</dc:creator>
      <dc:date>2024-02-20T15:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: Driving Distance and Time between residential addresses and health clinics using Google Maps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916999#M361204</link>
      <description>&lt;P&gt;The color in the editor might not make any difference.&amp;nbsp; The editor is NOT SAS.&amp;nbsp; It is just trying to guess how SAS will interpret your code and add colors based on those guesses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The beginning of your first macro makes no sense.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro distance_time;
 
%do j=1 %to 5 /*&amp;amp;Observations*/;
data _null_;
nrec = &amp;amp;j;
set Addresses point=nrec;
%let ll1=addr1;
%let ll2=addr2;
stop;
run;
 
filename x url "https://www.google.com/maps/dir/&amp;amp;ll1/&amp;amp;ll2/?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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro processor works BEFORE the resulting generated code is forwarded to SAS to interpret and run.&amp;nbsp; So that first data step does nothing since you actually ran this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do j=1 %to 5 /*&amp;amp;Observations*/;
%let ll1=addr1;
%let ll2=addr2;
data _null_;
nrec = &amp;amp;j;
set Addresses point=nrec;
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I suspect you wanted to do something like this instead.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do j=1 %to 5 /*&amp;amp;Observations*/;

data _null_;
  set Addresses firstobs=&amp;amp;j obs=&amp;amp;j;
  call symputx('ll1',addr1);
  call symputx('ll2',addr2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Feb 2024 16:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Driving-Distance-and-Time-between-residential-addresses-and/m-p/916999#M361204</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-20T16:17:30Z</dc:date>
    </item>
  </channel>
</rss>

