<?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: Left join with hash in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433329#M107410</link>
    <description>&lt;P&gt;dataset swap using your examples:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data c1 ;
 if _n_ = 1 then do ;
 if 0 then set a ;
 dcl hash b (dataset: "a", multidata: "y",ordered:'y') ;
 b.definekey ("key") ;
 b.definedata ("key","adata") ;
 b.definedone () ;
dcl hiter iter('b');
 end ;
 set b end=last;
 by key;
if  b.find()= 0 then do;
output;
if last.key   then b.remove();
end;
if last then do;
  rc = iter.first();
do while (rc = 0);
	call missing(bdata);
       output;
	  rc = iter.next();
   end;
end;
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 02 Feb 2018 00:09:55 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-02-02T00:09:55Z</dc:date>
    <item>
      <title>Left join with hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433315#M107408</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm kind new on hash usage and I was wondering if there is a way to perform a left join with hash without having to load the big table into hash instead the small one.&lt;/P&gt;
&lt;P&gt;I have been reading multiple papers and articles about this but I haven't been able to came up with an idea of how this could be performed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the code I have by now:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a ;
input key adata ;
cards ;
1 1
2 2
3 3
4 4
5 5
6 6
7 7
;
run ;
data b ;
input key bdata ;
cards ;
1 11
1 12
3 31
4 4
6 61
6 62
6 63
7 7
;
run ;


data c ;
 if _n_ = 1 then do ;
 if 0 then set b ;
 dcl hash b (dataset: "b", multidata: "y") ;
 b.definekey ("key") ;
 b.definedata ("bdata") ;
 b.definedone () ;
 end ;
 set a ;
 iorc = b.find() ;
 if iorc ne 0 then call missing (bdata) ;
 output ;
 do while (b.find_next() = 0) ;
 output ;
 end ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Both of the sample datasets are small here, but I was thinking in an scenario where big table is really big, so I can't load it into memory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestion? Thanks guys!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 23:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433315#M107408</guid>
      <dc:creator>iscgonzalez</dc:creator>
      <dc:date>2018-02-01T23:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: Left join with hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433317#M107409</link>
      <description>&lt;P&gt;which one in your example, would you consider big or small to simulate?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 23:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433317#M107409</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-01T23:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Left join with hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433329#M107410</link>
      <description>&lt;P&gt;dataset swap using your examples:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data c1 ;
 if _n_ = 1 then do ;
 if 0 then set a ;
 dcl hash b (dataset: "a", multidata: "y",ordered:'y') ;
 b.definekey ("key") ;
 b.definedata ("key","adata") ;
 b.definedone () ;
dcl hiter iter('b');
 end ;
 set b end=last;
 by key;
if  b.find()= 0 then do;
output;
if last.key   then b.remove();
end;
if last then do;
  rc = iter.first();
do while (rc = 0);
	call missing(bdata);
       output;
	  rc = iter.next();
   end;
end;
drop rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Feb 2018 00:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433329#M107410</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-02T00:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Left join with hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433332#M107412</link>
      <description>The a one is the small, it has no duplicates. It could be seen as a client's list and the other one transactions done by the users&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Feb 2018 00:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433332#M107412</guid>
      <dc:creator>iscgonzalez</dc:creator>
      <dc:date>2018-02-02T00:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Left join with hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433333#M107413</link>
      <description>&lt;P&gt;Ok so my assumption was right, I hope you have seen my code. Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 00:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433333#M107413</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-02T00:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: Left join with hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433537#M107492</link>
      <description>&lt;P&gt;Thanks!! that is a very nice approach to the solution, I guess I have to have the b table sorted to use this solution. But I think I can tweak a little the code using the find_next function to avoid the need of ordering it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, thank you for your awsome reply!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 14:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433537#M107492</guid>
      <dc:creator>iscgonzalez</dc:creator>
      <dc:date>2018-02-02T14:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Left join with hash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433612#M107519</link>
      <description>&lt;P&gt;And&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/58894"&gt;@iscgonzalez&lt;/a&gt;&amp;nbsp;Thank you for your very impressive attention to detail. I wish I could think out of the box like you. Anyway here is a version that doesn't require sort:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a ;
input key adata ;
cards ;
1 1
2 2
3 3
4 4
5 5
6 6
7 7
;
run ;

/*modified b dataset to make it unordered*/
data b ;
input key bdata ;
cards ;
1 11
6 61
1 12
3 31
6 62
4 4
6 63
7 7
;
run ;

data c2 ;
 if _n_ = 1 then do ;
 if 0 then set a ;
 dcl hash b (dataset: "a") ;
 b.definekey ("key") ;
 b.definedata ("key","adata") ;
 b.definedone () ;
dcl hiter iter('b');
 end ;
 do _n_=1 by 1 until(last);
 set b end=last;
 array t(100) ; /*this is arbitrary subscript number*/
if  b.find()= 0 then do;
if key not in t then t(_n_)=key;
output;
end;
if last then do;
	do _n_=1 to dim(t);
	if b.check(key:t(_n_))=0 then  b.remove(key:t(_n_));
	end;
	rc = iter.first();
	do while (rc = 0);
	call missing(bdata);
 	output;
 	rc = iter.next();
 	end;
end;
end;
drop rc t:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Feb 2018 17:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Left-join-with-hash/m-p/433612#M107519</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-02-02T17:26:13Z</dc:date>
    </item>
  </channel>
</rss>

