<?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: Division by zero error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303733#M270466</link>
    <description>&lt;P&gt;Ideal use for ifn()&lt;/P&gt;
&lt;PRE&gt;average_purchase=ifn(purchases_trx=0,0,purchases/purchases_trx);&lt;/PRE&gt;</description>
    <pubDate>Tue, 11 Oct 2016 08:48:12 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-10-11T08:48:12Z</dc:date>
    <item>
      <title>Division by zero error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303719#M270462</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;
&lt;P&gt;i am getting this kind of error:&lt;/P&gt;
&lt;P&gt;R: Limit set by ERRORS= option reached. Further errors of this type will not be printed.&lt;/P&gt;
&lt;P&gt;Division by zero detected at line 88 column 27&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mathematical operations could not be performed at the following places. The results of the&lt;BR /&gt;operations have been set to missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;2044 at 80:28&lt;BR /&gt;NOTE:&lt;/P&gt;
&lt;P&gt;my code is :&lt;/P&gt;
&lt;P&gt;data Y.Ce;&lt;BR /&gt;set Y.Cc;&lt;BR /&gt;Average_Purchase=(Purchases/Purchases_trx);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2016 07:05:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303719#M270462</guid>
      <dc:creator>Prateek1</dc:creator>
      <dc:date>2016-10-11T07:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303721#M270463</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89805"&gt;@Prateek1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;hi,&lt;/P&gt;
&lt;P&gt;i am getting this kind of error:&lt;/P&gt;
&lt;P&gt;R: Limit set by ERRORS= option reached. Further errors of this type will not be printed.&lt;/P&gt;
&lt;P&gt;Division by zero detected at line 88 column 27&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mathematical operations could not be performed at the following places. The results of the&lt;BR /&gt;operations have been set to missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;2044 at 80:28&lt;BR /&gt;NOTE:&lt;/P&gt;
&lt;P&gt;my code is :&lt;/P&gt;
&lt;P&gt;data Y.Ce;&lt;BR /&gt;set Y.Cc;&lt;BR /&gt;Average_Purchase=(Purchases/Purchases_trx);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The NOTE about the Limits is irrelevant. What's really important is/are the error message(s) BEFORE that.&lt;/P&gt;
&lt;P&gt;Please post the &lt;U&gt;whole&lt;/U&gt; log of the data step (redundant repeated messages can be omitted).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cancel that. "Division by zero" message not detected because of insufficient caffeine level. EBKAC.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2016 07:33:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303721#M270463</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-11T07:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303722#M270464</link>
      <description>&lt;P&gt;The Error is:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Division by zero &lt;/U&gt;&lt;/STRONG&gt;detected at line 88 column 27&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this happening in your calculation? If so, fix it so it doesn't.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2016 07:03:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303722#M270464</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-11T07:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Division by zero error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303724#M270465</link>
      <description>&lt;P&gt;The culprit is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Average_Purchase=(Purchases/Purchases_trx);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If Purchases_trx happens to be zero, this is an invalid calculation. A division by zero yields (per mathematical definition) infinity, which cannot be handled by SAS (and most other programming environments).&lt;/P&gt;
&lt;P&gt;So you need to either&lt;/P&gt;
&lt;P&gt;- remove observations where Purchases_trx is zero&lt;/P&gt;
&lt;P&gt;- or test if Purchases_trx is zero and than set a "default" value&lt;/P&gt;
&lt;P&gt;In your case I'd do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if Purchases_trx = 0
then Average_Purchase = 0;
else Average_Purchase = Purchases / Purchases_trx;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Oct 2016 07:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303724#M270465</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-11T07:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Division by zero error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303733#M270466</link>
      <description>&lt;P&gt;Ideal use for ifn()&lt;/P&gt;
&lt;PRE&gt;average_purchase=ifn(purchases_trx=0,0,purchases/purchases_trx);&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Oct 2016 08:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303733#M270466</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-11T08:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: Division by zero error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303747#M270467</link>
      <description>&lt;PRE&gt;average=divide(purchases,p&lt;WBR /&gt;urchases_trx);&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Oct 2016 11:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/303747#M270467</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-10-11T11:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: Division by zero error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/361484#M270468</link>
      <description>&lt;P&gt;IFN does not seem to prevent divide by zero errors when I use it. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
  x = 0;
  y = ifn(x = 0, 0, 1/x);
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This still generates an error in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;NOTE: Division by zero detected at line 35 column 22.
x=0 y=0 _ERROR_=1 _N_=1&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why? If X=0 then IFN should return 0 (second argument). The 1/X condition should never be evaluated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone please explain? Thanks very much.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 05:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/361484#M270468</guid>
      <dc:creator>SpaceMonkey</dc:creator>
      <dc:date>2017-05-25T05:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Division by zero error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/361499#M270469</link>
      <description>&lt;P&gt;It is a peculiarity of the ifn and ifc functions that they seem to always evaluate all expressions; this comes in handy when you need to conditionally use the result of a lag() function.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 08:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/361499#M270469</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-25T08:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Division by zero error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/361506#M270470</link>
      <description>&lt;P&gt;Its because its a function. &amp;nbsp;Normally the if statement is processed and stops when it needs to, i.e:&lt;/P&gt;
&lt;P&gt;if x=1 then do abc=3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;^ &amp;nbsp;^&lt;/P&gt;
&lt;P&gt;The compiler evaluates this part, and only moves onto the then if that is true. &amp;nbsp;The compiled function however is treated as a block ie:&lt;/P&gt;
&lt;P&gt;abc=ifn(x=1,3,0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;^ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ^&lt;/P&gt;
&lt;P&gt;The compiler treats the whole lot as condition/result due to being a function.&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/22856"&gt;@SpaceMonkey&lt;/a&gt;: Please dont re-open 8 month old topics for a new discussion, start a new topic.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 08:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/361506#M270470</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-25T08:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Division by zero error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/362400#M270472</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22856"&gt;@SpaceMonkey&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a thread is open, I'll comment on it. If you don't like that, tough for you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22856"&gt;@SpaceMonkey&lt;/a&gt;&amp;nbsp;Threads are never closed on here.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2017 01:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Division-by-zero-error/m-p/362400#M270472</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-29T01:10:47Z</dc:date>
    </item>
  </channel>
</rss>

