<?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 Proc SQL join with OR in where clause in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-join-with-OR-in-where-clause/m-p/464648#M118480</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 4 tables T1,T2,T3 and T4 and also a master table Z. The condition I have to join the tables to the master table is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;T1.ID1=Z.ID OR&amp;nbsp;&lt;SPAN&gt;T1.ID2=Z.ID OR&amp;nbsp;T1.ID3=Z.ID OR&amp;nbsp;T1.ID4=Z.ID&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there any way to optimize these type of joins? This join is taking too much time for me(&amp;gt; 1 hr).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The tables T1,T2,T3 and T4 have 100k obs and Z has 400k obs approx.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 24 May 2018 07:23:49 GMT</pubDate>
    <dc:creator>ADN</dc:creator>
    <dc:date>2018-05-24T07:23:49Z</dc:date>
    <item>
      <title>Proc SQL join with OR in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-join-with-OR-in-where-clause/m-p/464648#M118480</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 4 tables T1,T2,T3 and T4 and also a master table Z. The condition I have to join the tables to the master table is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;T1.ID1=Z.ID OR&amp;nbsp;&lt;SPAN&gt;T1.ID2=Z.ID OR&amp;nbsp;T1.ID3=Z.ID OR&amp;nbsp;T1.ID4=Z.ID&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there any way to optimize these type of joins? This join is taking too much time for me(&amp;gt; 1 hr).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The tables T1,T2,T3 and T4 have 100k obs and Z has 400k obs approx.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 07:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-join-with-OR-in-where-clause/m-p/464648#M118480</guid>
      <dc:creator>ADN</dc:creator>
      <dc:date>2018-05-24T07:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL join with OR in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-join-with-OR-in-where-clause/m-p/464653#M118482</link>
      <description>&lt;P&gt;How is the relationship between those tables with regards to id? one-to-one, one-to-many, or many-to-many?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on that, and the variables contained, sorting the tables by id and doing a data step merge might be the preferred solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you post some example data that shows the typical structures/contents (see my footnotes for converting datasets to data steps and posting the code). Just enough observations to clarify the issue.&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 07:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-join-with-OR-in-where-clause/m-p/464653#M118482</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-24T07:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL join with OR in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-join-with-OR-in-where-clause/m-p/464656#M118484</link>
      <description>&lt;P&gt;The master table Z is a union of all the ID's present in tables T1/T2/T3 and T4. ID's present in all the 5 tables are disctinct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately the data belongs to my client and I cant post it. But here is some sample data for the same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data T1;&lt;/P&gt;&lt;P&gt;input ID $20;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data T2;&lt;/P&gt;&lt;P&gt;input ID $20;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data T3;&lt;/P&gt;&lt;P&gt;input ID $20;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;7&lt;/P&gt;&lt;P&gt;8&lt;/P&gt;&lt;P&gt;9&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data T4;&lt;/P&gt;&lt;P&gt;input ID $20;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;11&lt;/P&gt;&lt;P&gt;12&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Z;&lt;/P&gt;&lt;P&gt;input ID $20;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;7&lt;/P&gt;&lt;P&gt;8&lt;/P&gt;&lt;P&gt;9&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;11&lt;/P&gt;&lt;P&gt;12&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 08:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-join-with-OR-in-where-clause/m-p/464656#M118484</guid>
      <dc:creator>ADN</dc:creator>
      <dc:date>2018-05-24T08:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL join with OR in where clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-join-with-OR-in-where-clause/m-p/464658#M118485</link>
      <description>&lt;P&gt;If the ID's in T1-T4 are mutually exclusive (like they look in your example), I'd first concatenate those datasets:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t1;
set t1-t4;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then sort/merge with Z:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=T;
by id;
run;

proc sort data=Z;
by id;
run;

data want;
merge
  Z (in=in_z)
  T
;
by id;
if in_z;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 May 2018 08:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-join-with-OR-in-where-clause/m-p/464658#M118485</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-24T08:18:06Z</dc:date>
    </item>
  </channel>
</rss>

