<?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 more than two tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241194#M44672</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo﻿&lt;/a&gt;&amp;nbsp;Thank you. &amp;nbsp;Have a good night.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Dec 2015 03:35:03 GMT</pubDate>
    <dc:creator>SAS_inquisitive</dc:creator>
    <dc:date>2015-12-30T03:35:03Z</dc:date>
    <item>
      <title>Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241160#M44652</link>
      <description>&lt;P&gt;I want merge three tables. In order to avoid sort procedure,I am inclined to use hash method. I have sucessfully used it for joining two tables.&amp;nbsp;I wonder if hash table can be used to join more than two tables.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2015 21:02:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241160#M44652</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-29T21:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241164#M44654</link>
      <description>Yes, I'm almost 100% sure.&lt;BR /&gt;In DI Studio the Lookup transformation uses hash tables, and are able to do lookup on several tables simultaneously.</description>
      <pubDate>Tue, 29 Dec 2015 21:33:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241164#M44654</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-12-29T21:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241166#M44655</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;&amp;nbsp;I don't &amp;nbsp;have access to DI studio. &amp;nbsp;Is it doable in Base SAS?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2015 21:38:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241166#M44655</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-29T21:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241168#M44657</link>
      <description>&lt;P&gt;Yes.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Dec 2015 21:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241168#M44657</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-12-29T21:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241169#M44658</link>
      <description>Absolutely. I was just bringing up the code generation from DI Studio as an example. Almost all code generated is in Base SAS code.</description>
      <pubDate>Tue, 29 Dec 2015 21:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241169#M44658</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-12-29T21:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241175#M44663</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo﻿&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;&amp;nbsp; Can you give an example (or DI generated code) so that I can apply in my cases? &amp;nbsp;Thanks !&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 00:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241175#M44663</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-30T00:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241176#M44664</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/64404"&gt;@SAS_inquisitive﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;If you know how to define and use one hash table then what holds you back to simply define and use a second hash table as well?&lt;/P&gt;
&lt;P&gt;You can load as much data into as many hash tables as you wish. The only restriction is memory available.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 00:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241176#M44664</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-12-30T00:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241183#M44665</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick﻿&lt;/a&gt;&amp;nbsp; I want to make sure I am doing correctly. I looked some papers (Paul Dorfman's), most of them have only two tables.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 01:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241183#M44665</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-30T01:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241185#M44666</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/64404"&gt;@SAS_inquisitive﻿&lt;/a&gt;: Have you tried yet? If you have and it did not work the way you want, show us what you have tried (code) and what didn't work (log). If you haven't tried, now it is the time for you to do so.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 02:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241185#M44666</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-12-30T02:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241188#M44668</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo﻿&lt;/a&gt;&amp;nbsp;I have not tried on more than two tables yet. &amp;nbsp;I will try to ceate some mock data sets (rather than real data sets) and will post the code. Here is one mock example.&lt;/P&gt;&lt;P&gt;This does not give desired result.&lt;/P&gt;&lt;PRE&gt;data a;
	input id x y;
	cards;
1 3 4
2 5 6
3 5 6
4 7 9
5 3 2
;

data b;
	input id x y;
	cards;
1 7 8
2 3 4
3 1 3
7 8 4
8 1 6
;

data c;
	input id x y;
	cards;
1 7 8
2 3 4
3 1 3
9 8 4
7 1 6
;

data test;
	if 0 then
		set a;
	if 0 then 
	    set b;

	if _n_=1 then
		do;
			dcl hash h1(dataset:'a');
			h1.definekey('id');
			h1.definedata('x','y');
				h1.definedone();

			dcl hash h2(dataset:'b');
			h2.definekey('id');
			h2.definedata('x','y');
				h2.definedone();
		end;

	set c;
	if h1.find() and h2.find() then output;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 02:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241188#M44668</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-30T02:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241193#M44671</link>
      <description>&lt;P&gt;Ok, that was nice try :). Couple of comments before SAS code:&lt;/P&gt;
&lt;P&gt;It is hard for me to guess&amp;nbsp;the purpose of your code without seeing your expected outcome. So here is my try:&lt;/P&gt;
&lt;P&gt;1. From your code, you seem trying to do a SQL equivalent of 'inner join' , however, your code is doing it exclusively instead. the commented part of the code will do a inclusive inner join.&lt;/P&gt;
&lt;P&gt;2. Since 3 of your incoming tables share exact variable names, so what you wound up doing is pdv is first overidden by h1 then by h2. What you want is probably to rename some of the variables to see some obvious outcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
	input id x_A y_A;
	cards;
1 3 4
2 5 6
3 5 6
4 7 9
5 3 2
;

data b;
	input id x_B y_B;
	cards;
1 7 8
2 3 4
3 1 3
7 8 4
8 1 6
;

data c;
	input id x_C y_C;
	cards;
1 7 8
2 3 4
3 1 3
9 8 4
7 1 6
;

data test;
	if 0 then
		set a B;

	/*	if 0 then */
	/*	    set b;*/
	if _n_=1 then
		do;
			dcl hash h1(dataset:'a');
			h1.definekey('id');
	h1.definedata(ALL:
			'Y');
			h1.definedone();
			dcl hash h2(dataset:'b');
			h2.definekey('id');
	h2.definedata(ALL:
			'y');
			h2.definedone();
		end;

	set c;

	if h1.find() and h2.find() then
		output;

	/*		 if h1.find()=0 and h2.find()=0 then output;*/
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Going bed right now, if you have further questions, I may find some time tomorrow.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 03:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241193#M44671</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-12-30T03:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241194#M44672</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo﻿&lt;/a&gt;&amp;nbsp;Thank you. &amp;nbsp;Have a good night.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 03:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241194#M44672</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-30T03:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Hash join more than two tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241309#M44707</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4877"&gt;@Haikuo﻿&lt;/a&gt;&amp;nbsp;states that the expected result should be the equivalent to a SQL inner join but then changes the selection logic so that it's no more an inner join. Must have been late...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would code as below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set c;
  if _n_=1 then
    do;
      if 0 then set a;
      dcl hash h1(dataset:'a');
      h1.definekey('id');
      h1.definedata(ALL:'Y');
      h1.definedone();

      if 0 then set b;
      dcl hash h2(dataset:'b');
      h2.definekey('id');
      h2.definedata(ALL:'y');
      h2.definedone();
    end;
  if h1.find()=0 and h2.find()=0 then output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The reason for having "set c;" first is that in case there are same named variables in the source datasets the definition from base table "c" will get used for the output dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In case the relationship between the tables can be 0:N and not only 0:1 then you would also have to use multidata&amp;amp;colon;'y' for the hash definition and code for some looping&amp;nbsp;over the hash as well in case there is a match where there are multiple entries for the same key in the hash.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2015 23:35:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hash-join-more-than-two-tables/m-p/241309#M44707</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-12-30T23:35:50Z</dc:date>
    </item>
  </channel>
</rss>

