<?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: Seeking Help With An Unusual Merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Seeking-Help-With-An-Unusual-Merge/m-p/379653#M276953</link>
    <description>&lt;P&gt;You might be able to do something with the geodist function although I've never used it and with such a large number of records to process i don't think any method is likely to be quick. The documentation for geodist is&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#n1korpfg2e18lon1nwpow9qijdxe.htm" target="_self"&gt;here&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jul 2017 08:58:23 GMT</pubDate>
    <dc:creator>ChrisBrooks</dc:creator>
    <dc:date>2017-07-27T08:58:23Z</dc:date>
    <item>
      <title>Seeking Help With An Unusual Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Seeking-Help-With-An-Unusual-Merge/m-p/379606#M276951</link>
      <description>&lt;P&gt;I am seeking help with an unusual merge/join.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets/tables in a Teradata environment, which I am communicating with using EG 7.11.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One table (let's call it CensusBlkMiss) contains about 2m records with location ID numbers, lat values, lon values, and is missing census block values:&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;ID&amp;nbsp;&amp;nbsp; Lat&amp;nbsp;&amp;nbsp; Lon&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 37 &amp;nbsp; &amp;nbsp;-120.7&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 37.2&amp;nbsp; -123.1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; 38 &amp;nbsp; &amp;nbsp;-122.2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp; 36.4&amp;nbsp; -119.8&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 35.9&amp;nbsp; -122.1&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;The other table (let's call it CensusBlkExist) contains about 10m records with lat values, lon values, and census block values:&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Lat&amp;nbsp;&amp;nbsp; Lon &amp;nbsp; &amp;nbsp; &amp;nbsp;CensusBlk&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;36.3&amp;nbsp; -121.7&amp;nbsp;&amp;nbsp; C2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;35.5&amp;nbsp; -120.9&amp;nbsp;&amp;nbsp; A8&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;38.2&amp;nbsp; -122&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A3&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;37.9 &amp;nbsp;-122.4&amp;nbsp;&amp;nbsp; C7&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;36.3&amp;nbsp; -121.9&amp;nbsp;&amp;nbsp; B6&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;37 &amp;nbsp; &amp;nbsp;-120.3 &amp;nbsp; A1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;36.6&amp;nbsp; -122.1&amp;nbsp;&amp;nbsp; B6&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;What I would like to do is assign census block values to the IDs in the first table based on the closest lat/long location from the second dataset, and end up with something like (let's call it CensusBlkCombo)&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;ID&amp;nbsp;&amp;nbsp; CensusBlk&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; A1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; B6&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; C7&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp; A1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; B6&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;("A1" is selected for ID #1 because 37/-120.3 is the closest location with a census block to 37/-120.7, the location of ID #1)&lt;BR /&gt;&lt;BR /&gt;I have not been able to think of a way to do this merge using normal SAS code.&lt;BR /&gt;&lt;BR /&gt;The SQL code that I have tried has been something like this&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc sql&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; create table CensusBlkCombo as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select A.SP_ID,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select CENSUS_BLK_GRP from&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;(select top 1 CENSUS_BLK_GRP&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from CensusBlkExist B&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by (abs(B.sp_lat - A.sp_lat2) + abs(B.sp_long - A.sp_long2))&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as CENSUS_BLK_GRP)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from CensusBlkMiss A));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;That particular code gives me an error message, "&lt;FONT face="courier new,courier"&gt;TOP N Syntax error: Top N option is not supported in subquery&lt;/FONT&gt;".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not wedded to that setup, though - any suggestions are welcome, including a radically different code structure welcome too.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 23:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Seeking-Help-With-An-Unusual-Merge/m-p/379606#M276951</guid>
      <dc:creator>Adam_Coutts</dc:creator>
      <dc:date>2017-07-26T23:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Seeking Help With An Unusual Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Seeking-Help-With-An-Unusual-Merge/m-p/379611#M276952</link>
      <description>&lt;P&gt;What country are you in? US? If so, look at PROC GINSIDE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The example maps to county/state but if you have the shapefiles for the blocks you can do a similar project. SAS may already have the US census shapes in the MAPS folder.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=grmapref&amp;amp;docsetVersion=9.4&amp;amp;docsetTarget=p0qjcc8hugcjb2n1x3bmuaar16f0.htm&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=grmapref&amp;amp;docsetVersion=9.4&amp;amp;docsetTarget=p0qjcc8hugcjb2n1x3bmuaar16f0.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/155987"&gt;@Adam_Coutts&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am seeking help with an unusual merge/join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two datasets/tables in a Teradata environment, which I am communicating with using EG 7.11.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One table (let's call it CensusBlkMiss) contains about 2m records with location ID numbers, lat values, lon values, and is missing census block values:&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;ID&amp;nbsp;&amp;nbsp; Lat&amp;nbsp;&amp;nbsp; Lon&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 37 &amp;nbsp; &amp;nbsp;-120.7&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 37.2&amp;nbsp; -123.1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; 38 &amp;nbsp; &amp;nbsp;-122.2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp; 36.4&amp;nbsp; -119.8&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 35.9&amp;nbsp; -122.1&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;The other table (let's call it CensusBlkExist) contains about 10m records with lat values, lon values, and census block values:&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Lat&amp;nbsp;&amp;nbsp; Lon &amp;nbsp; &amp;nbsp; &amp;nbsp;CensusBlk&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;36.3&amp;nbsp; -121.7&amp;nbsp;&amp;nbsp; C2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;35.5&amp;nbsp; -120.9&amp;nbsp;&amp;nbsp; A8&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;38.2&amp;nbsp; -122&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A3&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;37.9 &amp;nbsp;-122.4&amp;nbsp;&amp;nbsp; C7&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;36.3&amp;nbsp; -121.9&amp;nbsp;&amp;nbsp; B6&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;37 &amp;nbsp; &amp;nbsp;-120.3 &amp;nbsp; A1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;36.6&amp;nbsp; -122.1&amp;nbsp;&amp;nbsp; B6&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;What I would like to do is assign census block values to the IDs in the first table based on the closest lat/long location from the second dataset, and end up with something like (let's call it CensusBlkCombo)&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;ID&amp;nbsp;&amp;nbsp; CensusBlk&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; A1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; B6&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; C7&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp; A1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; B6&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;("A1" is selected for ID #1 because 37/-120.3 is the closest location with a census block to 37/-120.7, the location of ID #1)&lt;BR /&gt;&lt;BR /&gt;I have not been able to think of a way to do this merge using normal SAS code.&lt;BR /&gt;&lt;BR /&gt;The SQL code that I have tried has been something like this&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc sql&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; create table CensusBlkCombo as&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select A.SP_ID,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select CENSUS_BLK_GRP from&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;(select top 1 CENSUS_BLK_GRP&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from CensusBlkExist B&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by (abs(B.sp_lat - A.sp_lat2) + abs(B.sp_long - A.sp_long2))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as CENSUS_BLK_GRP)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from CensusBlkMiss A));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;That particular code gives me an error message, "&lt;FONT face="courier new,courier"&gt;TOP N Syntax error: Top N option is not supported in subquery&lt;/FONT&gt;".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not wedded to that setup, though - any suggestions are welcome, including a radically different code structure welcome too.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 23:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Seeking-Help-With-An-Unusual-Merge/m-p/379611#M276952</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-26T23:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: Seeking Help With An Unusual Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Seeking-Help-With-An-Unusual-Merge/m-p/379653#M276953</link>
      <description>&lt;P&gt;You might be able to do something with the geodist function although I've never used it and with such a large number of records to process i don't think any method is likely to be quick. The documentation for geodist is&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#n1korpfg2e18lon1nwpow9qijdxe.htm" target="_self"&gt;here&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2017 08:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Seeking-Help-With-An-Unusual-Merge/m-p/379653#M276953</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-07-27T08:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Seeking Help With An Unusual Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Seeking-Help-With-An-Unusual-Merge/m-p/386496#M276954</link>
      <description>&lt;P&gt;ChrisBrooks - thank you for your reply.&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;It looks to me like the geodist function would replace me ad hoc distance calculation (abs(B.sp_lat - A.sp_lat2) + abs(B.sp_long - A.sp_long2)) but is not set up to translate lat and long to census block.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Reeza - thank you for the reply as well.&amp;nbsp; &lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;PROC GINSIDE is indeed able to generate the census blocks that I was seeking.&amp;nbsp; And I was able to find census block maps for California at &lt;A href="ftp://ftp2.census.gov/geo/tiger/TIGER2010BLKPOPHU/" target="_blank"&gt;ftp://ftp2.census.gov/geo/tiger/TIGER2010BLKPOPHU/&lt;/A&gt;.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2017 06:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Seeking-Help-With-An-Unusual-Merge/m-p/386496#M276954</guid>
      <dc:creator>Adam_Coutts</dc:creator>
      <dc:date>2017-08-09T06:52:41Z</dc:date>
    </item>
  </channel>
</rss>

