06-03-2013 07:18 PM
I'm doing some computations using SAS. In my formula, I have to divide a variable which I know it is not ZERO. But because it is very very small, SAS recognizes it as a ZERO, and gives me errors when processing the calculation.
What can I do to make SAS to increase the degree of accuracy when dealing with numbers? Thanks!
06-03-2013 10:46 PM
As far as I know, SAS does all it's computations using double precision floating point numbers and never goes beyond that precision. Within those limits, it tries to avoid rounding error and numerical instability. The most common approach when dealing with very large or very small numbers involves rescaling your problem.
For example, in the following datastep, an error occurs only when z is calculated :
x = 1e-200;
y = 1e200;
t = 1 / x;
z = y / x;
06-03-2013 11:44 PM
Can you post an example of the calculation causing the problem? Dividing by a very small number may result in a very large number that could be meaningless in the context of how you want to use it.
06-04-2013 01:34 AM
Another thing you might try is changing the order of your computations. It may be that your very small numbers are intermediary results.
Also, it never hurts to go back to the assumptions of the model. Is it really meaningful in the real world problem you are trying to solve to divide by such a small number? Maybe there is a special condition in practice when measurements are very close to zero?
06-04-2013 11:52 AM
Here's another example. If you run this code, it quits after just over 1000 iterations, even though theoretically smallnum should never become zero. It's quite possible that the result that is causing you problems is actually zero.
All of the preceding advice is correct; you should consider ways to restructure your code.
smallnum = 1;
stopflag = 0;
do i = 1 to 1000000 while(stopflag = 0);
smallnum = smallnum / 2;
testnum = 1 / smallnum;
if smallnum = 0 then
stopflag = 1;