<?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: get rid of cartesian product join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/get-rid-of-cartesian-product-join/m-p/869740#M343550</link>
    <description>&lt;P&gt;See this alternative:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set QUERY_FOR_V2_FCT_CLM end=done;
if _n_ = 1
then do;
  length f1 /* define here, as it is in icd10 */;
  declare hash icd10 (dataset:"icd10");
  Idc10.definekey("f1");
  icd10.definedone();
  call missing(f1);
end;
if icd10.check(key:CLM_PRCDR_1_CD) = 0 or icd10.check(key:CLM_PRCDR_2_CD) = 0 then COUNT_of_BENE_SK + 1;
if done;
keep COUNT_of_BENE_SK;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 14 Apr 2023 10:34:37 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-04-14T10:34:37Z</dc:date>
    <item>
      <title>get rid of cartesian product join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-rid-of-cartesian-product-join/m-p/869722#M343541</link>
      <description>&lt;P&gt;I need to run this merge in sql and I'm getting a cartesian product join.&amp;nbsp; &amp;nbsp;I took the step of eliminating duplicates from one of the joined datasets, but I still getting the message on the cartesian product.&amp;nbsp; &amp;nbsp;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;27&lt;BR /&gt;28&lt;BR /&gt;29 PROC SQL;&lt;BR /&gt;30 CREATE TABLE ICD10_2 AS&lt;BR /&gt;31 SELECT DISTINCT F1&lt;BR /&gt;32 FROM ICD10;&lt;BR /&gt;NOTE: Table WORK.ICD10_2 created, with 265 rows and 1 columns.&lt;/P&gt;&lt;P&gt;33 /* CREATE TABLE WORK.QUERY_FOR_V2_FCT_CLM AS */&lt;BR /&gt;34 SELECT /* COUNT_of_BENE_SK */&lt;BR /&gt;35 (COUNT(t1.BENE_SK)) AS COUNT_of_BENE_SK&lt;BR /&gt;36 FROM QUERY_FOR_V2_FCT_CLM t1, WORK.ICD10_2 t2&lt;BR /&gt;37 WHERE (t1.CLM_PRCDR_1_CD = t2.F1&lt;BR /&gt;38 OR t1.CLM_PRCDR_2_CD = t2.F1);&lt;BR /&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized.&lt;BR /&gt;39 QUIT;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.13 seconds&lt;BR /&gt;cpu time 0.10 seconds&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 09:23:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-rid-of-cartesian-product-join/m-p/869722#M343541</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2023-04-14T09:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: get rid of cartesian product join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-rid-of-cartesian-product-join/m-p/869726#M343543</link>
      <description>&lt;P&gt;I assume you just want the number of valid&amp;nbsp;BENE_SK values from&amp;nbsp;QUERY_FOR_V2_FCT_CLM - so it may help to rewrite the join a simple WHERE clause:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
SELECT /* COUNT_of_BENE_SK */
 (COUNT(t1.BENE_SK)) AS COUNT_of_BENE_SK
 FROM QUERY_FOR_V2_FCT_CLM t1
 WHERE  CLM_PRCDR_1_CD in (select F1 from WORK.ICD10_2)
   or  CLM_PRCDR_2_CD in(select F1 from WORK.ICD10_2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Apr 2023 09:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-rid-of-cartesian-product-join/m-p/869726#M343543</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-04-14T09:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: get rid of cartesian product join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-rid-of-cartesian-product-join/m-p/869736#M343546</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9248"&gt;@Batman&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this query, it uses Boolean expression&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE ICD10_2 AS
	SELECT DISTINCT F1
	FROM ICD10;

	/* CREATE TABLE WORK.QUERY_FOR_V2_FCT_CLM AS */
	SELECT /* COUNT_of_BENE_SK */
	(COUNT(t1.BENE_SK)) AS COUNT_of_BENE_SK
	FROM QUERY_FOR_V2_FCT_CLM t1
	WHERE exists (select 'x' from WORK.ICD10_2 t2 where t1.CLM_PRCDR_1_CD = t2.F1
	OR t1.CLM_PRCDR_2_CD = t2.F1);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 10:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-rid-of-cartesian-product-join/m-p/869736#M343546</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-04-14T10:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: get rid of cartesian product join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-rid-of-cartesian-product-join/m-p/869740#M343550</link>
      <description>&lt;P&gt;See this alternative:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set QUERY_FOR_V2_FCT_CLM end=done;
if _n_ = 1
then do;
  length f1 /* define here, as it is in icd10 */;
  declare hash icd10 (dataset:"icd10");
  Idc10.definekey("f1");
  icd10.definedone();
  call missing(f1);
end;
if icd10.check(key:CLM_PRCDR_1_CD) = 0 or icd10.check(key:CLM_PRCDR_2_CD) = 0 then COUNT_of_BENE_SK + 1;
if done;
keep COUNT_of_BENE_SK;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Apr 2023 10:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-rid-of-cartesian-product-join/m-p/869740#M343550</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-14T10:34:37Z</dc:date>
    </item>
  </channel>
</rss>

