Date: Thu, 11 Apr 2002 14:07:00 -0400
Reply-To: "Dorfman, Paul" <Paul.Dorfman@BCBSFL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Dorfman, Paul" <Paul.Dorfman@BCBSFL.COM>
Subject: Re: Division by zero
Content-Type: text/plain; charset=iso-8859-1
Mia,
First, it is not a good idea to test a numeric variable, in this case, OSAL,
for being blank. Since it can't, you are making SAS implicitly convert the
blank literal to a numeric missing value using the BEST informat. So, I bet
you see conversion messages as well.
Now what you should do depends on what you want to see. If you want the
ratio to assume a missing value in the case the divisor is missing or zero,
you can code
perc = nsal / (osal min .) -1 ;
In this case, you will get rid of the 'zero divide' message if OSAL=0.
However, you will receive messages telling you that missing values were
generated if NSAL is misiing and/or OSAL is missing or zero. This is not
necessarily bad, because it tells you something about what is going on. If
you want no messages at all, then
if osal <= .z or osal = 0 then perc = . ;
else perc = sum (nsal, 0) / osal - 1 ;
Not so long ago I was surprised by a business analyst's rather bizarre
demand to teach her how to make a ratio equal to zero any time when either
numerator or denominator is zero or missing, with no log messages generated
to any effect. I just told her to code this
ratio = %ZDivide (x, y) ;
Behind the scenes, though, I had plugged this piece in the autocall library:
%Macro ZDivide (Numerator, Denominator) ;
( Sum ((&Numerator ), 0) * (Not Not (&Denominator))
/
Sum ((&Denominator), Not (&Denominator))
)
%Mend ZDivide ;
Kind regards,
=====================
Paul M. Dorfman
Jacksonville, FL
=====================
From mto [mailto:mto@ADMIN4.HSC.UTH.TMC.EDU]:
> I am working on the data where I need to find the increase/decrease in
> salary and its percentage. This is the data I have
>
> name old fte old salaries new fte
> new salaries
> xx
> .50 100.
> yy 1.00 160.
> .50 70.
>
> What I did was (old fte=ofte, old salaries=osal etc...):
>
> DATA STEP2; SET STEP1; BY NAME;
> RETAIN INCR PERC;
> FORMAT INCR COMMA10.;
> FORMAT PERC PERCENTAGE8.2;
> IF FIRST.NAME THEN DO;
> INCR=0; PERC=0;
> END;
> INCR=NSAL-OSAL;
> IF OSAL=' ' THEN OSAL=0;
> IF NSAL=' ' THEN NSAL=0;
> PERC=(NSAL-OSAL)/OSAL;
> IF LAST.NAME THEN OUTPUT;
>
> And I got a trillions of this message "Division by zero
> detected at line XXX column XXX"
>
> What should I do?
Blue Cross Blue Shield of Florida, Inc., and its subsidiary and
affiliate companies are not responsible for errors or omissions in this e-mail message. Any personal comments made in this e-mail do not reflect the views of Blue Cross Blue Shield of Florida, Inc.