```Date: Mon, 31 Oct 2005 16:44:20 -0500 Reply-To: Chang Chung Sender: "SAS(r) Discussion" From: Chang Chung Subject: Re: Trying to avoid division by zero... Comments: To: oseithedude@GMAIL.COM On Mon, 31 Oct 2005 12:59:33 -0800, oseithedude@GMAIL.COM wrote: >Hello, I have around 40 or so numeric variables in a small program I am >writing. >Basically, the variables are being created as follows: > >var1 = (a/(b*c)); >var2 = (f/(h*d)); >var3 = (dog/(cat*mouse)); >var4 = (k/(l*var1)); >etc.... > >and so on for about 40 variables. My problem is that, even though the >final data seems to be coming out correctly, I am getting thousands of >"Division by zero detected..." errors for the cases where the >denominator in the above equations equal zero. It turns out that if the >denominator for any of the equations is equal to 0, then the variable >actually does not need to be created anyway. Is it posible to write >simple code that prevents the above mathematical operations from being >performed if the denominator equals zero or do I have to encase each of >the 40 variables I am creating with an if... then statement for the >case that the variables in the denominator are equal to zero? >Appreciate any help in this matter, thanks!!! Hi, Julie, I think you answered your own question in the part: "It turns out that if the denomicator for any of the equations is equal to 0, then the variable ..." This would actually partition the data into two: observations that are used in the calculations, and observations which are not. I would distinguish these two groups of observations first and do the calculations on the former group only like: data one; set two; /* do something similar like this one to create a flag var */ inSample = not ((b=0) or (c=0) or (h=0) or (cat=0) or (mouse=0) or (L=0)); if inSample then do; /* do calculations */ end; else do; /* results set to missing */ end; run; If you save the inSample flag, then it will be useful later. Cheers, Chang ```

Back to: Top of message | Previous page | Main SAS-L page