<?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 inconsistent sql left join with a sum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/inconsistent-sql-left-join-with-a-sum/m-p/681148#M205998</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;When I do two times the same left join including a sum, I get slightly different output datasets.&amp;nbsp; Differences of smnt of max E-8 for numbers in thousands.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table tab3_time1 as 
    select
        t1.num_dman_finm,
        sum(t2.mnt) as smnt
    from local.tab1 as t1
    left join local.tab2 as t2
    on t1.num_dman_finm = t2.num_dman_finm
        and t1.num_pers_dfe = t2.num_pers_dfe
    group by t1.num_dman_finm
    order by t1.num_dman_finm
    ;
quit;
proc sql;
    create table tab3_time2 as 
    select
        t1.num_dman_finm,
        sum(t2.mnt) as smnt
    from local.tab1 as t1
    left join local.tab2 as t2
    on t1.num_dman_finm = t2.num_dman_finm
        and t1.num_pers_dfe = t2.num_pers_dfe
    group by t1.num_dman_finm
    order by t1.num_dman_finm
    ;
quit;
proc compare data=tab3_time1 compare=tab3_time2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The above proc sql are identical, except for the output name.&lt;/P&gt;&lt;P&gt;tab1 contains only &lt;CODE class=" language-sas"&gt;num_dman_finm&lt;/CODE&gt;&amp;nbsp;and&amp;nbsp;&lt;CODE class=" language-sas"&gt;num_pers_dfe&lt;/CODE&gt;.&amp;nbsp; Without duplicates.&lt;/P&gt;&lt;P&gt;tab2 contains&amp;nbsp;&lt;CODE class=" language-sas"&gt;num_dman_finm&lt;/CODE&gt;,&amp;nbsp;&lt;CODE class=" language-sas"&gt;num_pers_dfe&lt;/CODE&gt;&amp;nbsp;and &lt;CODE class=" language-sas"&gt;mnt&lt;/CODE&gt;.&amp;nbsp;&amp;nbsp;With key duplicates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;CODE class=" language-sas"&gt;num_dman_finm&lt;/CODE&gt;&amp;nbsp;and&amp;nbsp;&lt;CODE class=" language-sas"&gt;num_pers_dfe&lt;/CODE&gt;&amp;nbsp;are integer keys.&amp;nbsp;&amp;nbsp;&lt;CODE class=" language-sas"&gt;mnt&lt;/CODE&gt; are moneys amounts, with 2 decimals.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Shouldn't the same request produce the same output?&lt;/P&gt;&lt;P&gt;There are ~5000 differences in the output datasets of ~900 000.&lt;/P&gt;&lt;P&gt;Working on version 9.04.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Sep 2020 20:07:50 GMT</pubDate>
    <dc:creator>phil_de_choc</dc:creator>
    <dc:date>2020-09-02T20:07:50Z</dc:date>
    <item>
      <title>inconsistent sql left join with a sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/inconsistent-sql-left-join-with-a-sum/m-p/681148#M205998</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;When I do two times the same left join including a sum, I get slightly different output datasets.&amp;nbsp; Differences of smnt of max E-8 for numbers in thousands.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table tab3_time1 as 
    select
        t1.num_dman_finm,
        sum(t2.mnt) as smnt
    from local.tab1 as t1
    left join local.tab2 as t2
    on t1.num_dman_finm = t2.num_dman_finm
        and t1.num_pers_dfe = t2.num_pers_dfe
    group by t1.num_dman_finm
    order by t1.num_dman_finm
    ;
quit;
proc sql;
    create table tab3_time2 as 
    select
        t1.num_dman_finm,
        sum(t2.mnt) as smnt
    from local.tab1 as t1
    left join local.tab2 as t2
    on t1.num_dman_finm = t2.num_dman_finm
        and t1.num_pers_dfe = t2.num_pers_dfe
    group by t1.num_dman_finm
    order by t1.num_dman_finm
    ;
quit;
proc compare data=tab3_time1 compare=tab3_time2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The above proc sql are identical, except for the output name.&lt;/P&gt;&lt;P&gt;tab1 contains only &lt;CODE class=" language-sas"&gt;num_dman_finm&lt;/CODE&gt;&amp;nbsp;and&amp;nbsp;&lt;CODE class=" language-sas"&gt;num_pers_dfe&lt;/CODE&gt;.&amp;nbsp; Without duplicates.&lt;/P&gt;&lt;P&gt;tab2 contains&amp;nbsp;&lt;CODE class=" language-sas"&gt;num_dman_finm&lt;/CODE&gt;,&amp;nbsp;&lt;CODE class=" language-sas"&gt;num_pers_dfe&lt;/CODE&gt;&amp;nbsp;and &lt;CODE class=" language-sas"&gt;mnt&lt;/CODE&gt;.&amp;nbsp;&amp;nbsp;With key duplicates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;CODE class=" language-sas"&gt;num_dman_finm&lt;/CODE&gt;&amp;nbsp;and&amp;nbsp;&lt;CODE class=" language-sas"&gt;num_pers_dfe&lt;/CODE&gt;&amp;nbsp;are integer keys.&amp;nbsp;&amp;nbsp;&lt;CODE class=" language-sas"&gt;mnt&lt;/CODE&gt; are moneys amounts, with 2 decimals.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Shouldn't the same request produce the same output?&lt;/P&gt;&lt;P&gt;There are ~5000 differences in the output datasets of ~900 000.&lt;/P&gt;&lt;P&gt;Working on version 9.04.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 20:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/inconsistent-sql-left-join-with-a-sum/m-p/681148#M205998</guid>
      <dc:creator>phil_de_choc</dc:creator>
      <dc:date>2020-09-02T20:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: inconsistent sql left join with a sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/inconsistent-sql-left-join-with-a-sum/m-p/681160#M206005</link>
      <description>&lt;P&gt;This is odd. Are you saying that the results vary every time you run this query? In a random or systematic way?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 21:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/inconsistent-sql-left-join-with-a-sum/m-p/681160#M206005</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-09-02T21:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: inconsistent sql left join with a sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/inconsistent-sql-left-join-with-a-sum/m-p/681161#M206006</link>
      <description>&lt;P&gt;Unlike a data step, SQL does not have to process data in order.; it can also split a query and join the results at the end. Because the results may not be joined in the same order, the calculation (the sum here) performed is slightly different. And because computers have issues with &lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;decimal numerical precision&lt;/A&gt;, the order &lt;A href="https://www.pharmasug.org/proceedings/2014/CC/PharmaSUG-2014-CC50.pdf" target="_self"&gt;matters&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;I'd expect the difference to be lower though, around 1e-15 rather than 1e-8. That's many orders of magnitude higher, and that's where my explanation falls shorter than I'd like.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 23:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/inconsistent-sql-left-join-with-a-sum/m-p/681161#M206006</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-02T23:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: inconsistent sql left join with a sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/inconsistent-sql-left-join-with-a-sum/m-p/681164#M206007</link>
      <description>&lt;P&gt;1e-8 is the maximum reported by proc compare.&amp;nbsp; There were many differences around 1e-14.&amp;nbsp; And there were many amounts in the 100k or greater, not just 1k.&amp;nbsp; I'll verify at work tomorrow that the greatest differences are for the greatest amounts, and if so, mark your response as accepted answer.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 21:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/inconsistent-sql-left-join-with-a-sum/m-p/681164#M206007</guid>
      <dc:creator>phil_de_choc</dc:creator>
      <dc:date>2020-09-02T21:56:02Z</dc:date>
    </item>
  </channel>
</rss>

