<?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 Getting cartesian product in self join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-cartesian-product-in-self-join/m-p/893993#M353171</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;When i am trying to execute below code i am getting cartesian product while using inner join but i dont want cartesian, i need 6 rows only as it is with previous quarter comparision,&lt;/P&gt;
&lt;P&gt;I have sent output as well, but instead of 8 rows it should be 6 rows only&lt;/P&gt;
&lt;P&gt;Please help me on this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data t;&lt;BR /&gt;input id repdate $10. amount;&lt;BR /&gt;datalines;&lt;BR /&gt;1 31DEC2020 2000&lt;BR /&gt;1 31DEC2020 5000&lt;BR /&gt;1 31DEC2021 3000&lt;BR /&gt;1 30SEP2020 1500&lt;BR /&gt;1 30SEP2021 3000&lt;BR /&gt;1 30SEP2020 6000&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;data t1 (drop=repdate);&lt;BR /&gt;set t;&lt;BR /&gt;currqtr=input(repdate, date9.);&lt;BR /&gt;format currqtr date9.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table t2 as&lt;BR /&gt;select a.*,intnx("qtr",a.currqtr,-1,"e") as prevqtr format date9.,&lt;BR /&gt;coalesce (b.amount,0) as previoussale,&lt;BR /&gt;coalesce ((a.amount-b.amount)/b.amount,0) as growth format=percentn8.1&lt;BR /&gt;from t1 as a left join&lt;BR /&gt;t1 as b&lt;BR /&gt;on a.id = b.id and intnx("qtr",a.currqtr,-1,"e") = b.currqtr&lt;BR /&gt;order by id;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="harshpatel_0-1694583551782.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87862iC0BC353A99D41275/image-size/medium?v=v2&amp;amp;px=400" role="button" title="harshpatel_0-1694583551782.png" alt="harshpatel_0-1694583551782.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Sep 2023 05:40:14 GMT</pubDate>
    <dc:creator>harshpatel</dc:creator>
    <dc:date>2023-09-13T05:40:14Z</dc:date>
    <item>
      <title>Getting cartesian product in self join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-cartesian-product-in-self-join/m-p/893993#M353171</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;When i am trying to execute below code i am getting cartesian product while using inner join but i dont want cartesian, i need 6 rows only as it is with previous quarter comparision,&lt;/P&gt;
&lt;P&gt;I have sent output as well, but instead of 8 rows it should be 6 rows only&lt;/P&gt;
&lt;P&gt;Please help me on this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data t;&lt;BR /&gt;input id repdate $10. amount;&lt;BR /&gt;datalines;&lt;BR /&gt;1 31DEC2020 2000&lt;BR /&gt;1 31DEC2020 5000&lt;BR /&gt;1 31DEC2021 3000&lt;BR /&gt;1 30SEP2020 1500&lt;BR /&gt;1 30SEP2021 3000&lt;BR /&gt;1 30SEP2020 6000&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;data t1 (drop=repdate);&lt;BR /&gt;set t;&lt;BR /&gt;currqtr=input(repdate, date9.);&lt;BR /&gt;format currqtr date9.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table t2 as&lt;BR /&gt;select a.*,intnx("qtr",a.currqtr,-1,"e") as prevqtr format date9.,&lt;BR /&gt;coalesce (b.amount,0) as previoussale,&lt;BR /&gt;coalesce ((a.amount-b.amount)/b.amount,0) as growth format=percentn8.1&lt;BR /&gt;from t1 as a left join&lt;BR /&gt;t1 as b&lt;BR /&gt;on a.id = b.id and intnx("qtr",a.currqtr,-1,"e") = b.currqtr&lt;BR /&gt;order by id;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="harshpatel_0-1694583551782.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87862iC0BC353A99D41275/image-size/medium?v=v2&amp;amp;px=400" role="button" title="harshpatel_0-1694583551782.png" alt="harshpatel_0-1694583551782.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 05:40:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-cartesian-product-in-self-join/m-p/893993#M353171</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2023-09-13T05:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: Getting cartesian product in self join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-cartesian-product-in-self-join/m-p/893998#M353176</link>
      <description>&lt;P&gt;You have multiple entries per id and quarter, which have to be consolidated first for the process to result in meaningful output.&lt;/P&gt;
&lt;P&gt;First use PROC MEANS to calculate sums or averages, then do the compare.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 06:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-cartesian-product-in-self-join/m-p/893998#M353176</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-13T06:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: Getting cartesian product in self join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-cartesian-product-in-self-join/m-p/894003#M353180</link>
      <description>Thanks it works</description>
      <pubDate>Wed, 13 Sep 2023 07:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-cartesian-product-in-self-join/m-p/894003#M353180</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2023-09-13T07:39:57Z</dc:date>
    </item>
  </channel>
</rss>

