hi,
i am getting this kind of error:
R: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
Division by zero detected at line 88 column 27
Mathematical operations could not be performed at the following places. The results of the
operations have been set to missing values.
Each place is given by: (Number of times) at (Line):(Column).
2044 at 80:28
NOTE:
my code is :
data Y.Ce;
set Y.Cc;
Average_Purchase=(Purchases/Purchases_trx);
run;
Ideal use for ifn()
average_purchase=ifn(purchases_trx=0,0,purchases/purchases_trx);
@Prateek1 wrote:
hi,
i am getting this kind of error:
R: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
Division by zero detected at line 88 column 27
Mathematical operations could not be performed at the following places. The results of the
operations have been set to missing values.
Each place is given by: (Number of times) at (Line):(Column).
2044 at 80:28
NOTE:my code is :
data Y.Ce;
set Y.Cc;
Average_Purchase=(Purchases/Purchases_trx);
run;
The NOTE about the Limits is irrelevant. What's really important is/are the error message(s) BEFORE that.
Please post the whole log of the data step (redundant repeated messages can be omitted).
Cancel that. "Division by zero" message not detected because of insufficient caffeine level. EBKAC.
The Error is:
Division by zero detected at line 88 column 27
Is this happening in your calculation? If so, fix it so it doesn't.
The culprit is this:
Average_Purchase=(Purchases/Purchases_trx);
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).
So you need to either
- remove observations where Purchases_trx is zero
- or test if Purchases_trx is zero and than set a "default" value
In your case I'd do
if Purchases_trx = 0
then Average_Purchase = 0;
else Average_Purchase = Purchases / Purchases_trx;
Ideal use for ifn()
average_purchase=ifn(purchases_trx=0,0,purchases/purchases_trx);
IFN does not seem to prevent divide by zero errors when I use it. For example:
data test; x = 0; y = ifn(x = 0, 0, 1/x); run;
This still generates an error in the log:
NOTE: Division by zero detected at line 35 column 22. x=0 y=0 _ERROR_=1 _N_=1
Why? If X=0 then IFN should return 0 (second argument). The 1/X condition should never be evaluated.
Can someone please explain? Thanks very much.
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.
Its because its a function. Normally the if statement is processed and stops when it needs to, i.e:
if x=1 then do abc=3;
^ ^
The compiler evaluates this part, and only moves onto the then if that is true. The compiled function however is treated as a block ie:
abc=ifn(x=1,3,0)
^ ^
The compiler treats the whole lot as condition/result due to being a function.
@SpaceMonkey: Please dont re-open 8 month old topics for a new discussion, start a new topic.
@SpaceMonkey wrote:
If a thread is open, I'll comment on it. If you don't like that, tough for you.
@SpaceMonkey Threads are never closed on here.
average=divide(purchases,purchases_trx);
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.