<?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: Cartesian product not optomized in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-product-not-optomized/m-p/952674#M372301</link>
    <description>&lt;P&gt;The reason for this is your use of joining with the findw function. Let's look at a simple example that replicates this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bmw;
    set sashelp.cars;
    where make = 'BMW';
    drop horsepower;
run;

data bmw_hp;
    set sashelp.cars;
    where make = 'BMW';
    keep make model horsepower;
run;

proc sql;
    create table test as
        select t1.make, t1.model, t2.horsepower
        from bmw as t1
        LEFT JOIN
             bmw_hp as t2 
        ON findw(t1.model, trim(t2.model))
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For small tables this generally isn't a problem, but for big tables it can be a big issue. If your table is always going to be small then I wouldn't worry about it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get rid of this message you'll need to re-design your join, but since you're taking a variable from one table and checking if it has a word from another table for every row, I don't know if there is a great way to make this more efficient. I can think of ways to do this with, say, a hash table, but you're still doing a lot of looping to pull down every value from the lookup table to feed it into findw(), and it might even be less efficient than SQL.&lt;/P&gt;</description>
    <pubDate>Thu, 05 Dec 2024 21:58:57 GMT</pubDate>
    <dc:creator>Stu_SAS</dc:creator>
    <dc:date>2024-12-05T21:58:57Z</dc:date>
    <item>
      <title>Cartesian product not optomized</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-product-not-optomized/m-p/952662#M372295</link>
      <description>&lt;P&gt;This sql query seems to give me the desired output, but it also note below ("one or more Cartesian product joins that can&lt;BR /&gt;not be optimized") makes me wonder if something is amiss.&amp;nbsp; &amp;nbsp;Is there a fix to the code that will not generate the note?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;27 /*Assign Drug Categories where possible to Ingredients not&lt;BR /&gt;28 associated with a drug category*/&lt;BR /&gt;29 PROC SQL;&lt;BR /&gt;30 Create Table FDA_RESOLVED_Process as&lt;BR /&gt;31 SELECT FDA.Active_Ingredient&lt;BR /&gt;32 ,FDA.Initial_Posting_Date&lt;BR /&gt;33 ,FDA.Resolved_Date&lt;BR /&gt;34 /*if there is a match, put drug_category, if not use "Not on List"*/&lt;BR /&gt;35 , coalescec(EML.Drug_Category, 'Not in List') as Drug_Category&lt;BR /&gt;36 /*Ingredient list*/&lt;BR /&gt;37 FROM Fda_resolved_data_WO_Blank as FDA&lt;BR /&gt;38 /*Drug Category and Name list*/&lt;BR /&gt;39 LEFT JOIN Essential_medicines_list as EML&lt;BR /&gt;40 /*select if drug name from Essential Medicines is in Active Ingredient*/&lt;BR /&gt;41 ON findw(FDA.Active_Ingredient, trim(EML.DRUG_NAME_))&lt;BR /&gt;42 ;&lt;BR /&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can&lt;BR /&gt;not be optimized.&lt;BR /&gt;NOTE: Table WORK.FDA_RESOLVED_PROCESS created, with 129 rows and 4 columns.&lt;/P&gt;&lt;P&gt;43 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 19:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-product-not-optomized/m-p/952662#M372295</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2024-12-05T19:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Cartesian product not optomized</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cartesian-product-not-optomized/m-p/952674#M372301</link>
      <description>&lt;P&gt;The reason for this is your use of joining with the findw function. Let's look at a simple example that replicates this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bmw;
    set sashelp.cars;
    where make = 'BMW';
    drop horsepower;
run;

data bmw_hp;
    set sashelp.cars;
    where make = 'BMW';
    keep make model horsepower;
run;

proc sql;
    create table test as
        select t1.make, t1.model, t2.horsepower
        from bmw as t1
        LEFT JOIN
             bmw_hp as t2 
        ON findw(t1.model, trim(t2.model))
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For small tables this generally isn't a problem, but for big tables it can be a big issue. If your table is always going to be small then I wouldn't worry about it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get rid of this message you'll need to re-design your join, but since you're taking a variable from one table and checking if it has a word from another table for every row, I don't know if there is a great way to make this more efficient. I can think of ways to do this with, say, a hash table, but you're still doing a lot of looping to pull down every value from the lookup table to feed it into findw(), and it might even be less efficient than SQL.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 21:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cartesian-product-not-optomized/m-p/952674#M372301</guid>
      <dc:creator>Stu_SAS</dc:creator>
      <dc:date>2024-12-05T21:58:57Z</dc:date>
    </item>
  </channel>
</rss>

