<?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: Hash join with multiple tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-with-multiple-tables/m-p/521082#M141351</link>
    <description>&lt;P&gt;Can you show us the code for the inner, left and full joins you want to perform using hash objects?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That way, we know what to shoot for &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Dec 2018 09:03:43 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2018-12-13T09:03:43Z</dc:date>
    <item>
      <title>Hash join with multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-with-multiple-tables/m-p/521069#M141346</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kindly let me know, how to write the hash join for multiple tables.&lt;/P&gt;
&lt;P&gt;Joins could be inner join, Left join and full join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA A;&lt;BR /&gt;input Name $1. Salary Age PIN;&lt;BR /&gt;Cards;&lt;BR /&gt;A 200 20 40&lt;BR /&gt;B 300 30 60&lt;BR /&gt;C 400 40 80&lt;BR /&gt;D 500 50 100&lt;BR /&gt;E 600 60 120&lt;BR /&gt;F 700 70 140&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;
&lt;P&gt;DATA B;&lt;BR /&gt;input Name $1. Salary Grade $2. BIN;&lt;BR /&gt;Cards;&lt;BR /&gt;A 200 AA 20&lt;BR /&gt;G 800 GG 80&lt;BR /&gt;H 900 HH 90&lt;BR /&gt;I 1000 II 100&lt;BR /&gt;F 700 FF 70&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;
&lt;P&gt;DATA C;&lt;BR /&gt;input Name $1. dept;&lt;BR /&gt;Cards;&lt;BR /&gt;A 111&lt;BR /&gt;B 222&lt;BR /&gt;C 333&lt;BR /&gt;Z 000&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking for your kind support&amp;nbsp; as i am learning hash joins.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Uma Shanker Saini&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 06:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-with-multiple-tables/m-p/521069#M141346</guid>
      <dc:creator>umashankersaini</dc:creator>
      <dc:date>2018-12-13T06:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join with multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-with-multiple-tables/m-p/521076#M141348</link>
      <description>&lt;P&gt;Hi Umashanker,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code for inner join.hope so this will help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA A;
input Name $1. Salary Age PIN;
Cards;
A 200 20 40
B 300 30 60
C 400 40 80
D 500 50 100
E 600 60 120
F 700 70 140
;
Run;

DATA B;
input Name $1. Salary Grade $2. BIN;
Cards;
A 200 AA 20
G 800 GG 80
H 900 HH 90
I 1000 II 100
F 700 FF 70
;
Run;

DATA C;
input Name $1. dept;
Cards;
A 111
B 222
C 333
Z 000
;
RUN;

data want;
if 0 then set a b c;
declare hash h1(dataset:'C');
h1.definekey('name');
h1.defineDATA(all:'Y');
H1.DEFINEDONE();
declare hash h2(dataset:'b');
h2.definekey('name');
h2.DEFINEDATa(all:'Y');
h2.definedone();
DO UNTIL(LR);
set a END=LR;
if h1.find(key:name)=0 AND H2.FIND(KEY:NAME)=0 then output;
END;
STOP;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 07:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-with-multiple-tables/m-p/521076#M141348</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2018-12-13T07:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join with multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-with-multiple-tables/m-p/521082#M141351</link>
      <description>&lt;P&gt;Can you show us the code for the inner, left and full joins you want to perform using hash objects?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That way, we know what to shoot for &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 09:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-with-multiple-tables/m-p/521082#M141351</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-12-13T09:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join with multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-with-multiple-tables/m-p/521099#M141365</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for the output of following query :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Proc sql; &lt;BR /&gt;Create table ABC_SQL_INNER as &lt;BR /&gt;select A.name,A.Salary,B.Grade,B.Bin,C.Dept &lt;BR /&gt;from A&lt;BR /&gt;Inner join B&lt;BR /&gt;on A.Name=B.name&lt;BR /&gt;inner join C&lt;BR /&gt;on A.Name=C.name;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Proc sql; &lt;BR /&gt;Create table ABC_SQL_left as &lt;BR /&gt;select A.name,A.Salary,B.Grade,B.Bin,C.Dept &lt;BR /&gt;from A&lt;BR /&gt;left join B&lt;BR /&gt;on A.Name=B.name&lt;BR /&gt;left join C&lt;BR /&gt;on A.Name=C.name;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Proc sql; &lt;BR /&gt;Create table ABC_SQL_full as &lt;BR /&gt;select A.name,A.Salary,B.Grade,B.Bin,C.Dept &lt;BR /&gt;from A&lt;BR /&gt;full join B&lt;BR /&gt;on A.Name=B.name&lt;BR /&gt;full join C&lt;BR /&gt;on A.Name=C.name;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 10:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-with-multiple-tables/m-p/521099#M141365</guid>
      <dc:creator>umashankersaini</dc:creator>
      <dc:date>2018-12-13T10:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join with multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-with-multiple-tables/m-p/521111#M141372</link>
      <description>&lt;P&gt;You can do the inner and left joins like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA A;
input Name $1. Salary Age PIN;
Cards;
A 200 20 40
B 300 30 60
C 400 40 80
D 500 50 100
E 600 60 120
F 700 70 140
;
Run;

DATA B;
input Name $1. Salary Grade $2. BIN;
Cards;
A 200 AA 20
G 800 GG 80
H 900 HH 90
I 1000 II 100
F 700 FF 70
;
Run;

DATA C;
input Name $1. dept;
Cards;
A 111
B 222
C 333
Z 000
;
RUN;

/* Inner join */
Proc sql; 
Create table ABC_SQL_INNER as 
select A.name,A.Salary,B.Grade,B.Bin,C.Dept 
from A
Inner join B
on A.Name=B.name
inner join C
on A.Name=C.name;
quit;

data ABC_HASH_INNER(drop=rc:);
   if 0 then set B C;
   if _N_ = 1 then do;
      declare hash h1(dataset:"B");
      h1.defineKey('Name');
      h1.defineData('Grade', 'Bin');
      h1.defineDone();
      declare hash h2(dataset:"C");
      h2.defineKey('Name');
      h2.defineData('Dept');
      h2.defineDone();
   end;
   
   set A(keep=name Salary);

   rc1=h1.find();
   rc2=h2.find();

   if rc1=0 &amp;amp; rc2=0;
run;

proc compare base=ABC_SQL_INNER compare=ABC_HASH_INNER;
run;

/* Left join */
Proc sql; 
Create table ABC_SQL_left as 
select A.name,A.Salary,B.Grade,B.Bin,C.Dept 
from A
left join B
on A.Name=B.name
left join C
on A.Name=C.name;
quit;

data ABC_HASH_LEFT(drop=rc:);
   if 0 then set B C;
   if _N_ = 1 then do;
      declare hash h1(dataset:"B");
      h1.defineKey('Name');
      h1.defineData('Grade', 'Bin');
      h1.defineDone();
      declare hash h2(dataset:"C");
      h2.defineKey('Name');
      h2.defineData('Dept');
      h2.defineDone();
   end;
   
   set A(keep=name Salary);

   rc1=h1.find();
   rc2=h2.find();

   if rc1 ne 0 then call missing(Grade, Bin);
   if rc2 ne 0 then call missing(Dept);
run;

proc compare base=ABC_SQL_LEFT compare=ABC_HASH_LEFT;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Dec 2018 11:58:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-with-multiple-tables/m-p/521111#M141372</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-12-13T11:58:41Z</dc:date>
    </item>
  </channel>
</rss>

