<?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 Re: Distance between zip codes macro issue: runs for hours. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Distance-between-zip-codes-macro-issue-runs-for-hours/m-p/624936#M184159</link>
    <description>&lt;P&gt;Take the macro out of the problem.&amp;nbsp; Does it run for one pair of zip codes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really expect the TEMP data step to generate more than one observation?&amp;nbsp; If not then insert a STOP statement after the OUTPUT statement.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Feb 2020 20:16:34 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-02-14T20:16:34Z</dc:date>
    <item>
      <title>Distance between zip codes macro issue: runs for hours.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distance-between-zip-codes-macro-issue-runs-for-hours/m-p/624932#M184156</link>
      <description>&lt;P&gt;I'm trying to find the distance between 3,600 pairs of zipcodes, patient and their provider. I attached 50 pairs in a CSV file. Patient zipcode is patz, and provider zipcode is provz.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I run SAS 9.4 on Windows 10 in a VM using Parallels, so I'm used to things taking a little bit longer than they would when I run it on a Windows computer. Except I left it to run overnight last night, and it wasn't done seven hours later.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a problem with my code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname ob "\\Mac\Home\Desktop\SAS";

proc import file="\\Mac\Home\Desktop\zip.csv"
dbms=csv
out=zip
replace;
run;

data _null_;
call symputx('nzips',obs);
stop;
set zip nobs=obs;
run;

%macro distance_time (ds=, z1=, z2=, out=);
%do j=1 %to &amp;amp;nzips;
DATA _null_;
nrec = &amp;amp;j;
set zip point=nrec;
call symputx('patz',&amp;amp;z1);
call symputx('provz',&amp;amp;z2);
RUN;

filename x url "https://www.google.com/maps/dir/&amp;amp;z1/&amp;amp;z2/?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;

data temp;
keep z1 z2 distance units time;
z1="&amp;amp;z1";
z2="&amp;amp;z2";
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,'"');
 
  select;
   when (find(text,'d') ne 0)  time = sum(86400*input(scan(text,1,' '),best.), 
                                        3600*input(scan(text,3,' '),best.));
   when (find(text,'h') ne 0)  time = sum(3600*input(scan(text,1,' '),best.), 
                                        60*input(scan(text,3,' '),best.));
   otherwise                   time = 60*input(scan(text,1,' '),best.);
  end;
 
output; 
keep z1 z2 distance units time;
done:
output;
run;
 
filename x clear;
filename z clear;

proc append base=distance_time data=temp force;
run;
%end;
%mend;
 
%distance_time (ds=zip, z1=patz, z2=provz, out=dist_time);

data ob.distance_time;
set dist_time;
run;

proc export data=ob.distance_time
dbms=xlsx
outfile="\\Mac\Home\Desktop\distance.xlsx"
replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!!!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2020 19:52:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distance-between-zip-codes-macro-issue-runs-for-hours/m-p/624932#M184156</guid>
      <dc:creator>jesspurse</dc:creator>
      <dc:date>2020-02-14T19:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between zip codes macro issue: runs for hours.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distance-between-zip-codes-macro-issue-runs-for-hours/m-p/624935#M184158</link>
      <description>&lt;P&gt;The main thing wrong with your code is the structure. The program uses a macro loop to loop over pairs and computes the distance between pairs and then uses a formula to compute the distance and uses PROC APPEND to append the results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just create a data set that contains the pairs that you want to analyze and then process them all by using a single DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS&amp;gt; If you want to know why the macro loop + PROC APPEND method is so slow, see the article &lt;A href="https://blogs.sas.com/content/iml/2012/07/18/simulation-in-sas-the-slow-way-or-the-by-way.html" target="_self"&gt;"Simulation in SAS: The slow way or the BY way",&lt;/A&gt;&amp;nbsp;which analyzes macro loops in the context of simulation studies.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2020 20:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distance-between-zip-codes-macro-issue-runs-for-hours/m-p/624935#M184158</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-02-14T20:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between zip codes macro issue: runs for hours.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distance-between-zip-codes-macro-issue-runs-for-hours/m-p/624936#M184159</link>
      <description>&lt;P&gt;Take the macro out of the problem.&amp;nbsp; Does it run for one pair of zip codes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really expect the TEMP data step to generate more than one observation?&amp;nbsp; If not then insert a STOP statement after the OUTPUT statement.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2020 20:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distance-between-zip-codes-macro-issue-runs-for-hours/m-p/624936#M184159</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-14T20:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between zip codes macro issue: runs for hours.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distance-between-zip-codes-macro-issue-runs-for-hours/m-p/624945#M184160</link>
      <description>&lt;P&gt;And after you get this to work for&amp;nbsp; few pairs you might want to look into the SAS ZIPCITYDISTANCE function and see if the results differ by enough to be a problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   input patz provz;
   distance = zipcitydistance(patz,provz);
datalines;
28110 29403
28110 29440
28110 29520
;&lt;/PRE&gt;
&lt;P&gt;The distance returned is in miles.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-paragraph" id="p0526ai61vinhjn16k0835lbm34s"&gt;The ZIPCITYDISTANCE function returns the geodetic distance in miles between two ZIP code locations. The centroid of each ZIP code is used in the calculation.&lt;/DIV&gt;
&lt;DIV class="xis-paragraph" id="p1jf5fgd1qvjbin111xo4gv03r2u"&gt;The Sashelp.Zipcode data set must be present when you use this function. If you remove the data set, then ZIPCITYDISTANCE returns unexpected results.&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 14 Feb 2020 20:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distance-between-zip-codes-macro-issue-runs-for-hours/m-p/624945#M184160</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-14T20:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Distance between zip codes macro issue: runs for hours.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distance-between-zip-codes-macro-issue-runs-for-hours/m-p/624955#M184162</link>
      <description>&lt;P&gt;Note that Google is probably not happy with so many hits on its service from the same location.&amp;nbsp; It might well be slowing down its response or ignoring you all together.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2020 21:12:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distance-between-zip-codes-macro-issue-runs-for-hours/m-p/624955#M184162</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-14T21:12:39Z</dc:date>
    </item>
  </channel>
</rss>

