BookmarkSubscribeRSS Feed
grace_in_learning
Calcite | Level 5

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.

4 REPLIES 4
PGStats
Opal | Level 21

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

PG
SASKiwi
PROC Star

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.

LeoLopes
SAS Employee

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?

TomKari
Onyx | Level 15

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 2316 views
  • 0 likes
  • 5 in conversation