<?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: Why the sum value is not zero when it really is? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802080#M315722</link>
    <description>&lt;P&gt;Numeric precision.&lt;/P&gt;
&lt;P&gt;Well known issue though more predominate with decimal values. Some values just don't do will with the conversion to binary and so there is a loss of precision when the XX number of bytes used for numeric storage get full and truncate lower order digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not mention what format you attempted to apply but that would be one way such as F8. would round every result to no decimals at all.&lt;/P&gt;
&lt;P&gt;Or use the ROUND function on the sum. Hard to say what the solution might be as we don't know what your actual need is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Mar 2022 22:21:34 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-03-14T22:21:34Z</dc:date>
    <item>
      <title>Why the sum value is not zero when it really is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802067#M315713</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using PROC SQL to create the sum values for numeric variables, which contain both positive and negative values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My raw table looks like below:&lt;/P&gt;&lt;P&gt;Group&amp;nbsp; Date&amp;nbsp; &amp;nbsp; Var&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp;2/2/2022&amp;nbsp; -1&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp;2/2/2022&amp;nbsp; -3&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp;2/2/2022&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp;2/6/2022&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp;2/6/2022&amp;nbsp; -3&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp;2/6/2022&amp;nbsp; -2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm calculating the sum by group and date for var:&lt;/P&gt;&lt;P&gt;PROC SQL&lt;/P&gt;&lt;P&gt;SELECT DISTINCT GROUP,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DATE,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SUM(VAR) AS SUM&lt;/P&gt;&lt;P&gt;FROM RAW&lt;/P&gt;&lt;P&gt;GROUP BY GROUP, DATE;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I know the sum is zero for each group on each date. However, my result shows a scientific notation like&amp;nbsp;8.881784E-16 for each sum, which is very close to zero but does not equal to zero. I tried to change to format of my numeric variable but it didn't work. Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 21:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802067#M315713</guid>
      <dc:creator>huhuhu</dc:creator>
      <dc:date>2022-03-14T21:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Why the sum value is not zero when it really is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802068#M315714</link>
      <description>&lt;P&gt;Your numbers are not exactly integers. THere is some machine precision (also called &lt;A href="https://en.wikipedia.org/wiki/Machine_epsilon" target="_self"&gt;machine epsilon&lt;/A&gt;) going on here that can't be avoided on binary computers. This is nothing to worry about, it is perfectly normal.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 21:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802068#M315714</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-14T21:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why the sum value is not zero when it really is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802070#M315716</link>
      <description>&lt;P&gt;Most likely your data source comes from another platform like a data base.&lt;/P&gt;
&lt;P&gt;Because of differences in how floating point data gets stored there can be some very small as soon as you're dealing with decimals. &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lepg/p0dv87zb3bnse6n1mqo360be70qr.htm" target="_self"&gt;Here&lt;/A&gt; a start if you want to get into this topic.&lt;/P&gt;
&lt;P&gt;The way to get around this is to round the values to non-significant digits. Below an example how you you could go about this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data raw;
  input Group $ Date:ddmmyy10. Var;
  format date date9.;
  datalines;
A 2/2/2022 -1.00000000000001
A 2/2/2022 -3
A 2/2/2022 4
A 2/6/2022 5
A 2/6/2022 -3
A 2/6/2022 -2
;

PROC SQL;
  SELECT DISTINCT 
    GROUP,
    DATE,
    sum(var) as SUM,
    round(SUM(VAR),.000000000001) AS SUM2,
    SUM(round(VAR,.000000000001)) AS SUM3
  FROM RAW
  GROUP BY 
    GROUP, 
    DATE
    ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 21:36:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802070#M315716</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-03-14T21:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why the sum value is not zero when it really is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802072#M315718</link>
      <description>&lt;P&gt;SAS stores numbers in 8 bytes of storage, so it can hold up 15 digits accurately. So if your number is either longer than 15 digits, either as an integer or a decimal, it will not report accurately hence the tiny differences you are seeing beyond 15 digits. Using the ROUND function should remove tiny differences:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL
SELECT DISTINCT GROUP,
              DATE,
              round(SUM(VAR), 1) AS SUM
FROM RAW
GROUP BY GROUP, DATE;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Mar 2022 21:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802072#M315718</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-03-14T21:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why the sum value is not zero when it really is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802080#M315722</link>
      <description>&lt;P&gt;Numeric precision.&lt;/P&gt;
&lt;P&gt;Well known issue though more predominate with decimal values. Some values just don't do will with the conversion to binary and so there is a loss of precision when the XX number of bytes used for numeric storage get full and truncate lower order digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not mention what format you attempted to apply but that would be one way such as F8. would round every result to no decimals at all.&lt;/P&gt;
&lt;P&gt;Or use the ROUND function on the sum. Hard to say what the solution might be as we don't know what your actual need is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 22:21:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802080#M315722</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-14T22:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why the sum value is not zero when it really is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802085#M315725</link>
      <description>&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p0ji1unv6thm0dn1gp4t01a1u0g6.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/p0ji1unv6thm0dn1gp4t01a1u0g6.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 23:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802085#M315725</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2022-03-14T23:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why the sum value is not zero when it really is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802098#M315731</link>
      <description>&lt;P&gt;SAS has the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/p18pa7u3zufu9nn1ivv67uknw3i7.htm" target="_self"&gt;FUZZ function&lt;/A&gt; for dealing with values that are close to integers (see the doc)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
SELECT DISTINCT GROUP,
              DATE,
              SUM(FUZZ(VAR)) AS SUM
FROM RAW
GROUP BY GROUP, DATE;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Mar 2022 02:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802098#M315731</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-03-15T02:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why the sum value is not zero when it really is?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802194#M315794</link>
      <description>Thank you all for the recommendation! The round method works well. My numeric variables are with up to 6 decimals, which cause the problem.</description>
      <pubDate>Tue, 15 Mar 2022 13:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-sum-value-is-not-zero-when-it-really-is/m-p/802194#M315794</guid>
      <dc:creator>huhuhu</dc:creator>
      <dc:date>2022-03-15T13:40:47Z</dc:date>
    </item>
  </channel>
</rss>

