<?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: best practies to understand the difference between two number that appear the same in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848348#M335402</link>
    <description>&lt;P&gt;I get the same problem&lt;/P&gt;</description>
    <pubDate>Wed, 07 Dec 2022 14:15:44 GMT</pubDate>
    <dc:creator>Rakeon</dc:creator>
    <dc:date>2022-12-07T14:15:44Z</dc:date>
    <item>
      <title>best practies to understand the difference between two number that appear the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848336#M335398</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have two table,&lt;/P&gt;
&lt;P&gt;one has this value: a=2894378 and the second has this value: b = 28943.78.&lt;/P&gt;
&lt;P&gt;I make the join between them, and when i verify if they are equal :&lt;/P&gt;
&lt;P&gt;c = a / 100&lt;/P&gt;
&lt;P&gt;if&amp;nbsp; c = b&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sas interprets like different value.&lt;/P&gt;
&lt;P&gt;I try to change also the format, but after there are only 0 value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand why...&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 13:43:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848336#M335398</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2022-12-07T13:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: best practies to understand the difference between two number that appear the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848344#M335401</link>
      <description>Maybe try the other way around.&lt;BR /&gt;C = b * 100&lt;BR /&gt;Check if c = a</description>
      <pubDate>Wed, 07 Dec 2022 13:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848344#M335401</guid>
      <dc:creator>flyover</dc:creator>
      <dc:date>2022-12-07T13:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: best practies to understand the difference between two number that appear the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848348#M335402</link>
      <description>&lt;P&gt;I get the same problem&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 14:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848348#M335402</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2022-12-07T14:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: best practies to understand the difference between two number that appear the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848349#M335403</link>
      <description>&lt;P&gt;Could be a numeric precision issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try checking something like: if abs(c-b) &amp;lt; .000001&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then google / search lexjansen.com for SAS numeric precision.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 14:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848349#M335403</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-12-07T14:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: best practies to understand the difference between two number that appear the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848358#M335409</link>
      <description>&lt;P&gt;What is the actual FORMAT of the value when b=28943.78?&amp;nbsp; A format will display values as requested and may often round values. It may be the data actually has more decimals stored but you haven't examined them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run this program and examine the results:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  file print;
  do x=28943.778 to 28943.786 by 0.001;
     put "Format 10.3: " x= 10.3 " Format best8.: " x= best8.;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Dec 2022 15:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848358#M335409</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-12-07T15:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: best practies to understand the difference between two number that appear the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848366#M335414</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24745"&gt;@Rakeon&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that the &lt;EM&gt;exact&lt;/EM&gt; value of &lt;FONT face="courier new,courier"&gt;b&lt;/FONT&gt; is not equal to 28943.78, although it might be &lt;EM&gt;displayed&lt;/EM&gt; as 28943.78 with common formats such as BEST12.. Tiny deviations from the internal standard representation of a numeric value can easily result from calculations or data import from other platforms, external databases, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I compare numeric values where this might be an issue I usually apply the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0tj6cmga7p8qln1ejh6ebevm0c9.htm" target="_blank" rel="noopener"&gt;ROUND function&lt;/A&gt; with a suitable rounding unit to either or both sides of the equals sign (see code example below). Other options include checking the difference (as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;) or using the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0ifledavu3rv1n10gclzxbyy0ul.htm" target="_blank" rel="noopener"&gt;COMPFUZZ function&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's also good practice to remove those tiny errors as soon as they occur. That is, apply the ROUND function to affected variables after data import from an external database or to the result of a calculation (e.g.,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;total = &lt;STRONG&gt;round(&lt;/STRONG&gt;amount1 + amount2&lt;STRONG&gt;, 0.01)&lt;/STRONG&gt;&lt;/FONT&gt; if &lt;FONT face="courier new,courier"&gt;amount1&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;amount2&lt;/FONT&gt; have up to two decimals).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On Windows (or Unix) SAS I'd expect a quotient of a 7-digit integer divided by 100 to be "clean" in the sense that it should be equal to the corresponding decimal fraction with two decimals. (Please let me know if you find a counterexample on a different platform.) However, multiplying a&amp;nbsp;decimal fraction with two decimals by 100 will &lt;EM&gt;not&lt;/EM&gt; be equal to the expected integer in a substantial number of cases, e.g,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;0.07*100 ne 7&lt;/FONT&gt; is &lt;EM&gt;true&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;622   data _null_;
623   a=2894378;
624   b=28943.78;
625   c=a/100;
626   d=20000.08+8943.70;
627   e=b*100;
628   f=d*100;
629   put (a--f) (=hex16. /);
630   put (d f) (=best12. /);
631   if b=round(d,1e-9) then put 'OK';
632   diff=d-b;
633   put diff=;
634   run;

a=4146151500000000
b=40DC43F1EB851EB8
c=40DC43F1EB851EB8
d=40DC43F1EB851EB9
e=4146151500000000
f=4146151500000001
d=28943.78
f=2894378
OK
diff=3.637979E-12&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The HEX16. format is ideal for diagnosing such issues. As shown in the log above, the calculated value &lt;FONT face="courier new,courier"&gt;d&lt;/FONT&gt; is slightly too large (by 2**-38=3.6...E-12) due to a rounding error, but common formats (even BEST32. or 32.26) don't reveal this error because they slightly round values. The equality &lt;FONT face="courier new,courier"&gt;e=a&lt;/FONT&gt; holds in this particular case, but could fail with similar numbers. Variable &lt;FONT face="courier new,courier"&gt;f&lt;/FONT&gt; shows the risk of not caring about "unclean" values such as &lt;FONT face="courier new,courier"&gt;d&lt;/FONT&gt;: The rounding error has propagated and now affects what should actually be an integer value (so that &lt;FONT face="courier new,courier"&gt;a ne f&lt;/FONT&gt;). Again, the seemingly clean BEST12. display is treacherous. The rounding unit 1E-9 is greater than &lt;FONT face="courier new,courier"&gt;diff&lt;/FONT&gt;&amp;nbsp;and also small enough to preserve relevant decimals. So it is suitable for removing this error.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2022 15:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/best-practies-to-understand-the-difference-between-two-number/m-p/848366#M335414</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-12-07T15:58:30Z</dc:date>
    </item>
  </channel>
</rss>

