<?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: Machine Precision errors in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Machine-Precision-errors/m-p/146029#M38792</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your answers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know that the problem is produced by IEEE floating point, my question is if exist any way to avoid it without putting in each operation a ROUND function.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Feb 2015 08:01:26 GMT</pubDate>
    <dc:creator>arodriguez</dc:creator>
    <dc:date>2015-02-02T08:01:26Z</dc:date>
    <item>
      <title>Machine Precision errors</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Machine-Precision-errors/m-p/146026#M38789</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Today I was testing some calculations, I want to add a flag variable to indicate when a p-value is &amp;lt;=0.05 or &amp;lt;=0.01 and i found a machine precision error. An example to duplicate the error could be&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _N_&amp;lt;5 then new_var=age;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if _N_&amp;lt;10 then new_var=0.1-_N_/100;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if _N_&amp;lt;=15 then new_var=0.05-_N_/300;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else new_var=0.001-_N_/100000;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if new_var&amp;gt;0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if new_var &amp;lt;= 0.001 then flag = '***';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if new_var &amp;lt;= 0.01&amp;nbsp; then flag = '**';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if new_var &amp;lt;= 0.05&amp;nbsp; then flag = '*';&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are two lines with value "equal" to 0.01 but if I make a IF condition keeping rows with value equal to 0.01 and I don't get nothing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm wondering if there are any usual procedure to avoid this or a good practice to avoid this kind of problems, rather than round to each operation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Jan 2015 15:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Machine-Precision-errors/m-p/146026#M38789</guid>
      <dc:creator>arodriguez</dc:creator>
      <dc:date>2015-01-30T15:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Machine Precision errors</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Machine-Precision-errors/m-p/146027#M38790</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;What I presume you are hitting here, and I am just leaving so don't have SAS open, is where a number looks on screen like it is correct, however there is a really, really tiny change some 10 decimal places down.&amp;nbsp; So you may see in your table: 0.0001345, but the data stored is 0.000134500000012. &lt;/P&gt;&lt;P&gt;My solution is to use a rounding function to ensure the value is actually as you expect it.&amp;nbsp; So in your example new_var=round(0.05 - _N_ / 300,0.01).&amp;nbsp; This will ensure the tiny fraction doesn't hang on to annoy your calculations further on. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Jan 2015 15:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Machine-Precision-errors/m-p/146027#M38790</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-01-30T15:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Machine Precision errors</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Machine-Precision-errors/m-p/146028#M38791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not an error, a feature.&amp;nbsp; This is a feature of IEEE floating point operations and the fact that some number in base10 cannot be represented identically in base2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS stores all numbers a floating point.&amp;nbsp; base10 and base2 can represent base10 integers identically, but not all base10 decimal numbers.&amp;nbsp; This reference will tell you more than you want to know about how SAS handles precision&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/67885/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t01a1u0g6.htm" title="http://support.sas.com/documentation/cdl/en/lrcon/67885/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t01a1u0g6.htm"&gt;SAS(R) 9.4 Language Reference: Concepts, Fourth Edition&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Jan 2015 15:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Machine-Precision-errors/m-p/146028#M38791</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2015-01-30T15:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Machine Precision errors</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Machine-Precision-errors/m-p/146029#M38792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your answers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know that the problem is produced by IEEE floating point, my question is if exist any way to avoid it without putting in each operation a ROUND function.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Feb 2015 08:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Machine-Precision-errors/m-p/146029#M38792</guid>
      <dc:creator>arodriguez</dc:creator>
      <dc:date>2015-02-02T08:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Machine Precision errors</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Machine-Precision-errors/m-p/146030#M38793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since SAS just has floating point data type, yes, to be 100% sure, you need to round it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Feb 2015 11:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Machine-Precision-errors/m-p/146030#M38793</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-02-02T11:50:34Z</dc:date>
    </item>
  </channel>
</rss>

