- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
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!
Grace.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 :
data _null_;
x = 1e-200;
y = 1e200;
t = 1 / x;
z = y / x;
run;
PG
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
Tom
data nums;
smallnum = 1;
stopflag = 0;
do i = 1 to 1000000 while(stopflag = 0);
smallnum = smallnum / 2;
testnum = 1 / smallnum;
output;
if smallnum = 0 then
stopflag = 1;
end;
run;