<?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 Case When statement for an Inner Join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Case-When-statement-for-an-Inner-Join/m-p/857641#M338880</link>
    <description>&lt;P&gt;I have a join on a couple tables that takes FOREVER to run. Way way longer than it should and one of the notes I haven't noticed before states:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not sure what that means exactly but a quick google indicates that it probably isn't what I'm trying to accomplish.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.TABLE3 AS
	SELECT t1.*,
		   t2.NAME,
		   t2.DATE
	FROM WORK.TABLE1 t1 INNER JOIN
		 WORK.TABLE2 t2 ON (CASE WHEN t1.CAT1 NOT IN ('CATA', 'CATB') THEN (t1.ID1 = t2.ID1 AND t1.ID2= t2.ID2 AND t2.ID3 = t1.ID3)
							  WHEN t1.CAT1 IN ('CATA', 'CATB') THEN (t1.ID1 = t2.ID1 AND t1.ID2 = t2.ID2)
						 END);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is this an acceptable way to join? Is there a better way?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Tue, 07 Feb 2023 19:14:16 GMT</pubDate>
    <dc:creator>mhoward2</dc:creator>
    <dc:date>2023-02-07T19:14:16Z</dc:date>
    <item>
      <title>Case When statement for an Inner Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-When-statement-for-an-Inner-Join/m-p/857641#M338880</link>
      <description>&lt;P&gt;I have a join on a couple tables that takes FOREVER to run. Way way longer than it should and one of the notes I haven't noticed before states:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not sure what that means exactly but a quick google indicates that it probably isn't what I'm trying to accomplish.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.TABLE3 AS
	SELECT t1.*,
		   t2.NAME,
		   t2.DATE
	FROM WORK.TABLE1 t1 INNER JOIN
		 WORK.TABLE2 t2 ON (CASE WHEN t1.CAT1 NOT IN ('CATA', 'CATB') THEN (t1.ID1 = t2.ID1 AND t1.ID2= t2.ID2 AND t2.ID3 = t1.ID3)
							  WHEN t1.CAT1 IN ('CATA', 'CATB') THEN (t1.ID1 = t2.ID1 AND t1.ID2 = t2.ID2)
						 END);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is this an acceptable way to join? Is there a better way?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 19:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-When-statement-for-an-Inner-Join/m-p/857641#M338880</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2023-02-07T19:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Case When statement for an Inner Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-When-statement-for-an-Inner-Join/m-p/857655#M338884</link>
      <description>&lt;P&gt;CASE in a join is not a good idea. Just do a normal join:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.TABLE3 AS
   SELECT t1.*,
		  t2.NAME,
		  t2.DATE
   FROM WORK.TABLE1 t1 
   INNER JOIN WORK.TABLE2 t2 
   ON (t1.CAT1 NOT IN ('CATA', 'CATB') and t1.ID1 = t2.ID1 AND t1.ID2= t2.ID2 AND t2.ID3 = t1.ID3)
   or (t1.CAT1 IN ('CATA', 'CATB') and t1.ID1 = t2.ID1 AND t1.ID2 = t2.ID2)
   ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Feb 2023 20:13:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-When-statement-for-an-Inner-Join/m-p/857655#M338884</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-07T20:13:30Z</dc:date>
    </item>
  </channel>
</rss>

