<?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: find nearest zip with provider in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510655#M137435</link>
    <description>&lt;P&gt;So this is the SAS code I ended up using. Excel file "one" is zip (all), lat and long. Excel file "two" is zip (that have providers), lat and long.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import 
datafile ="one.xlsx"
dbms = xlsx
out = one
replace;
run;

proc import 
datafile ="two.xlsx"
dbms = xlsx
out = two
replace;
run;

proc sql;
create table mixed as
select one.*,two.zip as zip2, geodist(one.lata,  one.longa, two.latb, two.longb, 'M') as dist 
from one as one
cross join two as two
order by one.zip;
quit;

data cross;
set mixed;
drop lata longa;
run;

proc sort data=cross;
by zip dist;
Run;

data crosskeep;
set cross;
by zip;
if first.zip;
run;

proc export
data=crosskeep
outfile="cross.xlsx"
dbms = xlsx
replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This gave me a table with actual zip, closest zip, distance to closest zip. Would there have been an easier way?&lt;/P&gt;</description>
    <pubDate>Tue, 06 Nov 2018 00:15:49 GMT</pubDate>
    <dc:creator>jesspurse</dc:creator>
    <dc:date>2018-11-06T00:15:49Z</dc:date>
    <item>
      <title>find nearest zip with provider</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510257#M137326</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of zip codes and whether or not they have a provider (1 for yes, 0 for no). If providerinzip = 0, then I need to find the closest zip code that has a provider. I am unsure if nearest neighbor would work because I'm not looking for the nearest zip but one where providerinzip=1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I need to calculate the distance, but I know how to do that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached csv file of data.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Nov 2018 17:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510257#M137326</guid>
      <dc:creator>jesspurse</dc:creator>
      <dc:date>2018-11-04T17:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: find nearest zip with provider</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510280#M137337</link>
      <description>&lt;P&gt;I would:&lt;/P&gt;
&lt;P&gt;1. Download&amp;nbsp;the latitude/longitude of each ZIP code from a&amp;nbsp;reputable source&lt;/P&gt;
&lt;P&gt;2. Use the geodist function to calculate the&amp;nbsp;distance between ZIP codes&lt;/P&gt;</description>
      <pubDate>Sun, 04 Nov 2018 21:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510280#M137337</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-11-04T21:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: find nearest zip with provider</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510291#M137341</link>
      <description>&lt;P&gt;Right, I know how to do that. My issue is that there's 420some odd zip codes. That will take hours of manual work to find the closest zip with a provider for each zip that doesn't have one. I was looking for a way for SAS to calculate the closest zip.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Nov 2018 23:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510291#M137341</guid>
      <dc:creator>jesspurse</dc:creator>
      <dc:date>2018-11-04T23:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: find nearest zip with provider</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510292#M137342</link>
      <description>&lt;P&gt;geodist does that calculation. Keep the lowest distance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's missing?&lt;/P&gt;</description>
      <pubDate>Sun, 04 Nov 2018 23:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510292#M137342</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-11-04T23:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: find nearest zip with provider</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510307#M137344</link>
      <description>&lt;P&gt;Reading the documentation on GEODIST should help your understanding:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1korpfg2e18lon1nwpow9qijdxe.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1korpfg2e18lon1nwpow9qijdxe.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Nov 2018 02:45:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510307#M137344</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-11-05T02:45:43Z</dc:date>
    </item>
    <item>
      <title>Re: find nearest zip with provider</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510483#M137378</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I would:&lt;/P&gt;
&lt;P&gt;1. Download&amp;nbsp;the latitude/longitude of each ZIP code from a&amp;nbsp;reputable source&lt;/P&gt;
&lt;P&gt;2. Use the geodist function to calculate the&amp;nbsp;distance between ZIP codes&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SASHELP.ZIPCODE has lat/long for centroid of zip codes though you may want to download the latest version from SAS support.&lt;/P&gt;
&lt;P&gt;This set is very likely in the SAS install used.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The function ZIPCITYDISTANCE may be easier than GEODIST unless using an older version of SAS without the function.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Nov 2018 16:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510483#M137378</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-05T16:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: find nearest zip with provider</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510582#M137413</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Too easy! So many US-specific data sets and functions! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Nov 2018 02:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510582#M137413</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-11-06T02:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: find nearest zip with provider</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510647#M137432</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;Too easy! So many US-specific data and functions! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's good to live in the country that designs the software...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IIRC,&amp;nbsp;when the SASHELP.ZIPCODE set is not available several of the Zip code related functions don't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A sneaky implication might be that replacing SASHELP.ZIPCODE with a custom set might allow some of the functionality elsewhere.&lt;/P&gt;
&lt;P&gt;I know it is possible to replace the data set because there are updates on the SAS tech support site with instructions...&lt;/P&gt;</description>
      <pubDate>Mon, 05 Nov 2018 23:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510647#M137432</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-11-05T23:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: find nearest zip with provider</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510655#M137435</link>
      <description>&lt;P&gt;So this is the SAS code I ended up using. Excel file "one" is zip (all), lat and long. Excel file "two" is zip (that have providers), lat and long.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import 
datafile ="one.xlsx"
dbms = xlsx
out = one
replace;
run;

proc import 
datafile ="two.xlsx"
dbms = xlsx
out = two
replace;
run;

proc sql;
create table mixed as
select one.*,two.zip as zip2, geodist(one.lata,  one.longa, two.latb, two.longb, 'M') as dist 
from one as one
cross join two as two
order by one.zip;
quit;

data cross;
set mixed;
drop lata longa;
run;

proc sort data=cross;
by zip dist;
Run;

data crosskeep;
set cross;
by zip;
if first.zip;
run;

proc export
data=crosskeep
outfile="cross.xlsx"
dbms = xlsx
replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This gave me a table with actual zip, closest zip, distance to closest zip. Would there have been an easier way?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Nov 2018 00:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-nearest-zip-with-provider/m-p/510655#M137435</guid>
      <dc:creator>jesspurse</dc:creator>
      <dc:date>2018-11-06T00:15:49Z</dc:date>
    </item>
  </channel>
</rss>

