how can I fix if there are zeros in b? I want to change b=1 when b=0 and run this code when b>0.
Code:
if (a < 1000 OR
(a/b <.1 & c < 5000000 & d IN (0,.)) OR
(a/b < .1 & c < 10000000 & d IN (0,.)) OR
(a < 500000 & c < 5000000 & d IN (0,.)) OR
(a < 1000000 & c < 10000000 & d IN (0,.))) then e = 1;
Log:
NOTE: Division by zero detected at line 1393 column 29.
NOTE: Division by zero detected at line 1394 column 29.
@sasuser1031 wrote:
how can I fix if there are zeros in b? I want to change b=1 when b=0 and run this code when b>0.
Code:
if (a < 1000 OR(a/b <.1 & c < 5000000 & d IN (0,.)) OR
(a/b < .1 & c < 10000000 & d IN (0,.)) OR
(a < 500000 & c < 5000000 & d IN (0,.)) OR
(a < 1000000 & c < 10000000 & d IN (0,.))) then e = 1;
Log:
NOTE: Division by zero detected at line 1393 column 29.
NOTE: Division by zero detected at line 1394 column 29.
Before this IF statement, use
b=b*(b>0) + (b=0);
So if b>0, we use the value of b. If b=0 we use the value 1.
Hi @sasuser1031
Once you've changed b=0 to b=1, do you want to run the code for this new value of b, or do you want to run this code only when b is initially different from 0?
If it is the first cas, you can try the below code.
Best,
data want;
set have;
if b=0 then b=1;
if b>0 then do;
if (a < 1000) OR
(a/b <.1 & c < 5000000 & d IN (0,.)) OR
(a/b < .1 & c < 10000000 & d IN (0,.)) OR
(a < 500000 & c < 5000000 & d IN (0,.)) OR
(a < 1000000 & c < 10000000 & d IN (0,.)) then e = 1;
end;
run;
I want to run the code for both.
Using function DIVIDE() instead.
if (a < 1000 OR
( divide(a,b) <.1 & c < 5000000 & d IN (0,.)) OR
( divide(a,b) < .1 & c < 10000000 & d IN (0,.)) OR
(a < 500000 & c < 5000000 & d IN (0,.)) OR
(a < 1000000 & c < 10000000 & d IN (0,.))) then e = 1;
So you want to change the zeros in B to ones?
if b=0 then b=1;
If you do first that then your code will run without any divide by zeros.
if (a<1000)
or (((a/b)<0.1) and (c< 5000000) and d in (., 0))
or (((a/b)<0.1) and (c<10000000) and d in (., 0))
or ((a< 500000) and (c< 5000000) and d in (., 0))
or ((a<1000000) and (c<10000000) and d in (., 0))
then e=1
;
If you only want to do it only when B is > 0 then add that to the code. Note that if you test after you have change the zeros to ones then B will now be > 0.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.