<?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 Left outer join in hash table with duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243349#M45239</link>
    <description>&lt;P&gt;I want to peform left outer join in hash with following code (so as to reproduce the result of left join in Proc Sql). &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;input key d1 d2 d3;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 1 1&lt;BR /&gt;1 2 2 2&lt;BR /&gt;1 3 3 3&lt;BR /&gt;2 1 1 1&lt;BR /&gt;2 2 2 2&lt;BR /&gt;4 1 1 1&lt;BR /&gt;4 1 1 1&lt;BR /&gt;5 5 5 5&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data b;&lt;BR /&gt;input key d4 d5 d6 other;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 1 1 0&lt;BR /&gt;2 2 2 2 0&lt;BR /&gt;3 3 3 3 0&lt;BR /&gt;4 4 4 4 0&lt;BR /&gt;;&lt;BR /&gt;data test(drop=rc);&lt;BR /&gt;if 0 then set A;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;dcl hash h(dataset:'A',multidata&amp;amp;colon;'yes');&lt;BR /&gt;h.definekey('key');&lt;BR /&gt;h.definedata('d1','d2','d3');&lt;BR /&gt;h.definedone();&lt;BR /&gt;end;&lt;BR /&gt;set B (keep=key d4 d5 d6);&lt;BR /&gt;rc=h.find();&lt;BR /&gt;do while(rc=0);&lt;BR /&gt;output;&lt;BR /&gt;rc=h.find_next();&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jan 2016 21:58:15 GMT</pubDate>
    <dc:creator>SAS_inquisitive</dc:creator>
    <dc:date>2016-01-13T21:58:15Z</dc:date>
    <item>
      <title>Left outer join in hash table with duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243349#M45239</link>
      <description>&lt;P&gt;I want to peform left outer join in hash with following code (so as to reproduce the result of left join in Proc Sql). &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;input key d1 d2 d3;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 1 1&lt;BR /&gt;1 2 2 2&lt;BR /&gt;1 3 3 3&lt;BR /&gt;2 1 1 1&lt;BR /&gt;2 2 2 2&lt;BR /&gt;4 1 1 1&lt;BR /&gt;4 1 1 1&lt;BR /&gt;5 5 5 5&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data b;&lt;BR /&gt;input key d4 d5 d6 other;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 1 1 0&lt;BR /&gt;2 2 2 2 0&lt;BR /&gt;3 3 3 3 0&lt;BR /&gt;4 4 4 4 0&lt;BR /&gt;;&lt;BR /&gt;data test(drop=rc);&lt;BR /&gt;if 0 then set A;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;dcl hash h(dataset:'A',multidata&amp;amp;colon;'yes');&lt;BR /&gt;h.definekey('key');&lt;BR /&gt;h.definedata('d1','d2','d3');&lt;BR /&gt;h.definedone();&lt;BR /&gt;end;&lt;BR /&gt;set B (keep=key d4 d5 d6);&lt;BR /&gt;rc=h.find();&lt;BR /&gt;do while(rc=0);&lt;BR /&gt;output;&lt;BR /&gt;rc=h.find_next();&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2016 21:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243349#M45239</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-01-13T21:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: Left outer join in hash table with duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243375#M45256</link>
      <description>&lt;P&gt;Based on that A is your lookup table&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data new_test1(drop=rc r);
if 0 then set a;
declare hash hh_pat(dataset:"a", &lt;SPAN&gt;multidata&lt;/SPAN&gt;&lt;SPAN&gt;: "y"&lt;/SPAN&gt;);
rc=hh_pat.defineKey("key");
rc=hh_pat.defineData("d1", "d2", "d3");
rc=hh_pat.defineDone();
 
do until(eof);
 	set b end=eof;
 	call missing(d1, d2, d3); 
 	rc=hh_pat.find();
 	output;
	if (rc = 0) then do;
		hh_pat.has_next(result: r);
			do while(r ne 0);
				hh_pat.find_next();
 				output;
				hh_pat.has_next(result: r);
			end;
	end;
end;
stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should be identical to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
select b.key, a.d1, a.d2, a.d3 , b.d4, b.d5 , b.d6
from b left join a
on b.key=a.key;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 01:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243375#M45256</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-01-14T01:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Left outer join in hash table with duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243376#M45257</link>
      <description>&lt;P&gt;Your code looks good. Except:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;input key d1 d2 d3;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 1 1&lt;BR /&gt;1 2 2 2&lt;BR /&gt;1 3 3 3&lt;BR /&gt;2 1 1 1&lt;BR /&gt;2 2 2 2&lt;BR /&gt;4 1 1 1&lt;BR /&gt;4 1 1 1&lt;BR /&gt;5 5 5 5&lt;BR /&gt;;&lt;BR /&gt;data b;&lt;BR /&gt;input key d4 d5 d6 other;&lt;BR /&gt;datalines;&lt;BR /&gt;1 1 1 1 0&lt;BR /&gt;2 2 2 2 0&lt;BR /&gt;3 3 3 3 0&lt;BR /&gt;4 4 4 4 0&lt;BR /&gt;;&lt;BR /&gt;data test(drop=rc);&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;if 0 then set A;&lt;BR /&gt;dcl hash h(dataset:'A',multidata&amp;amp;colon;'yes');&lt;BR /&gt;h.definekey('key');&lt;BR /&gt;h.definedata('d1','d2','d3');&lt;BR /&gt;h.definedone();&lt;BR /&gt;end;&lt;BR /&gt;&lt;STRONG&gt;call missing(of _all_);&lt;/STRONG&gt;&lt;BR /&gt;set B (keep=key d4 d5 d6);&lt;BR /&gt;rc=h.find();&lt;BR /&gt;&lt;STRONG&gt;if rc ne 0 then output;&lt;/STRONG&gt;&lt;BR /&gt;do while(rc=0);&lt;BR /&gt;output;&lt;BR /&gt;rc=h.find_next();&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 01:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243376#M45257</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-01-14T01:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: Left outer join in hash table with duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243466#M45266</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49185"&gt;@mohamed_zaki﻿&lt;/a&gt;. &amp;nbsp;Thanks. &amp;nbsp;I also want this way too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;sql&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;select&lt;/SPAN&gt; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;key&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;d1&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;d2&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;d3 &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;d4&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;d5 &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; b&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;d6
&lt;SPAN class="token keyword"&gt;from&lt;/SPAN&gt; a &lt;SPAN class="token function"&gt;left&lt;/SPAN&gt; join b
on a&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;key&lt;SPAN class="token operator"&gt;=&lt;SPAN style="line-height: 20px;"&gt;b&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;key&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;quit&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 14:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243466#M45266</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-01-14T14:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Left outer join in hash table with duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243477#M45267</link>
      <description>&lt;P&gt;As your lookup table B is not having duplicate, then this is easier&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test(drop=rc);
 if 0 then set b;
 declare hash hh_pat(dataset:"b");
 rc=hh_pat.defineKey("key");
 rc=hh_pat.defineData("d4", "d5", "d6","other");
 rc=hh_pat.defineDone();
 do until(eof);
 set a end=eof;
 call missing(d4, d5, d6, other);
 rc=hh_pat.find();
 output;
 end;
 stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or you can modify the previous post code if you will have duplicate.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 15:12:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243477#M45267</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-01-14T15:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: Left outer join in hash table with duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243512#M45282</link>
      <description>&lt;P&gt;@ mohamed_zaki, I guess we can't do this while keeping data set &amp;nbsp;"a" in hash table, right?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 16:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243512#M45282</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2016-01-14T16:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Left outer join in hash table with duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243517#M45284</link>
      <description>&lt;P&gt;Yes, as &lt;STRONG&gt;A&lt;/STRONG&gt; contains duplicate records based on your&amp;nbsp;key. So you will end up&amp;nbsp;with uncomplete left joined data set. Only if you do specify the option&amp;nbsp;multidata="Y". And by that t&lt;SPAN&gt;he hash object keeps the multiple values in a list that is associated with the key. Which can be traversed and manipulated by using several methods such as HAS_NEXT or FIND_NEXT as in the first post.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jan 2016 17:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-outer-join-in-hash-table-with-duplicates/m-p/243517#M45284</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2016-01-14T17:24:35Z</dc:date>
    </item>
  </channel>
</rss>

