<?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 Formula evaluates(totals) the same set of variables differently whereas I should get same result in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Formula-evaluates-totals-the-same-set-of-variables-differently/m-p/761258#M240853</link>
    <description>&lt;PRE&gt;data have(keep= ln_no BKR_TRUSTEE_BA BKR_PPPMT_SUSP_BA BKR_DEBTOR_BA LN_SUSPENSE_BA MSP_Susp_BK_Sus);
set Suspense3;
if BKR_TRUSTEE_BA + BKR_PPPMT_SUSP_BA + BKR_DEBTOR_BA = LN_SUSPENSE_BA then MSP_Susp_BK_Sus = 1 ;else MSP_Susp_BK_Sus = 0;
if ln_no in ('9212','0129');
run;&lt;/PRE&gt;
&lt;P&gt;The output is as follows:&lt;/P&gt;
&lt;TABLE width="689"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;LN_NO&lt;/TD&gt;
&lt;TD width="117"&gt;LN_SUSPENSE_BA&lt;/TD&gt;
&lt;TD width="112"&gt;BKR_DEBTOR_BA&lt;/TD&gt;
&lt;TD width="115"&gt;BKR_TRUSTEE_BA&lt;/TD&gt;
&lt;TD width="145"&gt;BKR_PPPMT_SUSP_BA&lt;/TD&gt;
&lt;TD width="123"&gt;MSP_Susp_BK_Sus&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;9612&lt;/TD&gt;
&lt;TD&gt;315.07&lt;/TD&gt;
&lt;TD&gt;43.59&lt;/TD&gt;
&lt;TD&gt;233.71&lt;/TD&gt;
&lt;TD&gt;37.77&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;129&lt;/TD&gt;
&lt;TD&gt;223.02&lt;/TD&gt;
&lt;TD&gt;223.02&lt;/TD&gt;
&lt;TD&gt;0.00&lt;/TD&gt;
&lt;TD&gt;0.00&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Please forgive as I cannot replicate the issue using sashelp or a sample dataset.&amp;nbsp; I ran this from an existing program and modified the ln_no for security..&amp;nbsp; if BKR_TRUSTEE_BA + BKR_PPPMT_SUSP_BA + BKR_DEBTOR_BA = LN_SUSPENSE_BA then MSP_Susp_BK_Sus = 1 ;else MSP_Susp_BK_Sus = 0.&amp;nbsp; as you can see it works for the second ln_no 129 however I should also get a 1 for the first entry too. Yet I get a 0.&amp;nbsp; It appears sas is saying the there is a difference based on the above formula.&amp;nbsp; However there is no difference.&amp;nbsp; Does anyone know why sas would take the exact same statement and evaluate them differently??&lt;/P&gt;</description>
    <pubDate>Thu, 12 Aug 2021 19:51:06 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2021-08-12T19:51:06Z</dc:date>
    <item>
      <title>Formula evaluates(totals) the same set of variables differently whereas I should get same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-evaluates-totals-the-same-set-of-variables-differently/m-p/761258#M240853</link>
      <description>&lt;PRE&gt;data have(keep= ln_no BKR_TRUSTEE_BA BKR_PPPMT_SUSP_BA BKR_DEBTOR_BA LN_SUSPENSE_BA MSP_Susp_BK_Sus);
set Suspense3;
if BKR_TRUSTEE_BA + BKR_PPPMT_SUSP_BA + BKR_DEBTOR_BA = LN_SUSPENSE_BA then MSP_Susp_BK_Sus = 1 ;else MSP_Susp_BK_Sus = 0;
if ln_no in ('9212','0129');
run;&lt;/PRE&gt;
&lt;P&gt;The output is as follows:&lt;/P&gt;
&lt;TABLE width="689"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;LN_NO&lt;/TD&gt;
&lt;TD width="117"&gt;LN_SUSPENSE_BA&lt;/TD&gt;
&lt;TD width="112"&gt;BKR_DEBTOR_BA&lt;/TD&gt;
&lt;TD width="115"&gt;BKR_TRUSTEE_BA&lt;/TD&gt;
&lt;TD width="145"&gt;BKR_PPPMT_SUSP_BA&lt;/TD&gt;
&lt;TD width="123"&gt;MSP_Susp_BK_Sus&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;9612&lt;/TD&gt;
&lt;TD&gt;315.07&lt;/TD&gt;
&lt;TD&gt;43.59&lt;/TD&gt;
&lt;TD&gt;233.71&lt;/TD&gt;
&lt;TD&gt;37.77&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;129&lt;/TD&gt;
&lt;TD&gt;223.02&lt;/TD&gt;
&lt;TD&gt;223.02&lt;/TD&gt;
&lt;TD&gt;0.00&lt;/TD&gt;
&lt;TD&gt;0.00&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Please forgive as I cannot replicate the issue using sashelp or a sample dataset.&amp;nbsp; I ran this from an existing program and modified the ln_no for security..&amp;nbsp; if BKR_TRUSTEE_BA + BKR_PPPMT_SUSP_BA + BKR_DEBTOR_BA = LN_SUSPENSE_BA then MSP_Susp_BK_Sus = 1 ;else MSP_Susp_BK_Sus = 0.&amp;nbsp; as you can see it works for the second ln_no 129 however I should also get a 1 for the first entry too. Yet I get a 0.&amp;nbsp; It appears sas is saying the there is a difference based on the above formula.&amp;nbsp; However there is no difference.&amp;nbsp; Does anyone know why sas would take the exact same statement and evaluate them differently??&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 19:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-evaluates-totals-the-same-set-of-variables-differently/m-p/761258#M240853</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-08-12T19:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Formula evaluates(totals) the same set of variables differently whereas I should get same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-evaluates-totals-the-same-set-of-variables-differently/m-p/761268#M240859</link>
      <description>&lt;P&gt;Possible machine precision issue?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/comparing-two-values/m-p/761113#M240787" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/comparing-two-values/m-p/761113#M240787&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if fuzz(BKR_TRUSTEE_BA + BKR_PPPMT_SUSP_BA + BKR_DEBTOR_BA - LN_SUSPENSE_BA) = 0 then MSP_Susp_BK_Sus = 1 ;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 21:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-evaluates-totals-the-same-set-of-variables-differently/m-p/761268#M240859</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-12T21:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Formula evaluates(totals) the same set of variables differently whereas I should get same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-evaluates-totals-the-same-set-of-variables-differently/m-p/761279#M240867</link>
      <description>If it's possible for any of those values to be missing you may want to use a SUM() function instead of operator as well. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Aug 2021 20:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-evaluates-totals-the-same-set-of-variables-differently/m-p/761279#M240867</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-12T20:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Formula evaluates(totals) the same set of variables differently whereas I should get same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-evaluates-totals-the-same-set-of-variables-differently/m-p/761286#M240870</link>
      <description>&lt;P&gt;For future reference, SAS will return 1 for true and 0 for false for a comparison, so instead of&lt;/P&gt;
&lt;PRE&gt;if BKR_TRUSTEE_BA + BKR_PPPMT_SUSP_BA + BKR_DEBTOR_BA = LN_SUSPENSE_BA then MSP_Susp_BK_Sus = 1 ;else MSP_Susp_BK_Sus = 0;&lt;/PRE&gt;
&lt;P&gt;You might try&lt;/P&gt;
&lt;PRE&gt;MSP_Susp_BK_Sus = Sum( BKR_TRUSTEE_BA, BKR_PPPMT_SUSP_BA, BKR_DEBTOR_BA) = LN_SUSPENSE_BA);&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Aug 2021 20:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-evaluates-totals-the-same-set-of-variables-differently/m-p/761286#M240870</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-12T20:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: Formula evaluates(totals) the same set of variables differently whereas I should get same result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-evaluates-totals-the-same-set-of-variables-differently/m-p/761364#M240925</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;has nailed it. It's a typical rounding issue due to &lt;EM&gt;numeric representation error&lt;/EM&gt; in the numbers involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DATA step below, using your example numbers, shows how a sum A+B+C can be different from B+C+A on a computer in spite of the well known commutative law. It also demonstrates that standard formats, unlike HEX16., often hide the issue (all sums look the same) and how the ROUND function with a suitable rounding unit can help to avoid the issue. In your case, if there are only up to two decimals, 0.01 can be a suitable rounding unit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
retain a b c;
input s_ a b c;
s1=a+b+c;
s0=b+c+a;
d=s0-s1;
rs=round(s0,1e-8);
put (s: rs d)(=/)//
    (s: rs)(=hex16./);
cards;
315.07 43.59 233.71 37.77
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result (obtained with SAS 9.4 under Windows)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;s_=315.07
s1=315.07
s0=315.07
rs=315.07
d=5.684342E-14

s_=4073B11EB851EB85
s1=4073B11EB851EB85
s0=4073B11EB851EB8&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;6&lt;/FONT&gt;&lt;/STRONG&gt;
rs=4073B11EB851EB85&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Aug 2021 07:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-evaluates-totals-the-same-set-of-variables-differently/m-p/761364#M240925</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-08-13T07:56:43Z</dc:date>
    </item>
  </channel>
</rss>

