SAS Optimization, and SAS Simulation Studio

turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-03-2013 07:18 PM

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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to grace_in_learning

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 :

**data _null_;**

**x = 1e-200;**

**y = 1e200;**

**t = 1 / x;**

**z = y / x;**

**run;**

PG

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PGStats

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to grace_in_learning

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to grace_in_learning

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.

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;