2

See below for for some example code:

PROC SQL noprint;
          CREATE TABLE check AS
    
                SELECT *, round(var1,1e16) + round(var2,1e16) as final
    
                FROM dir.A;
    
    QUIT; RUN;

The numbers I am adding are -3.0584695E31 and 3.058469E31 and I get a sum of 4.5035996E15 but in reality, the sum should be on the order of ~1000.

lord12
  • 2,837
  • 9
  • 35
  • 47

2 Answers2

1

All numbers in SAS are floating point values with a precision of about 16 ditits. This corresponds to "double precision" in most programming languages and databases.

When calculating with values of around 1E31, you should expect an error of around 1E31/1E16, i.e. 1E15.

Dirk Horsten
  • 3,753
  • 4
  • 20
  • 37
1

What you want to do is, rather, round the result. Rounding the intermediary steps is mostly irrelevant - you'll still have some fuzziness in the space between the two rounded numbers, unless it happens to be already a precise difference. You may not see much difference in some cases, but in other cases you'll see a lot of difference (particularly when you expect, for example, the two numbers to sum to zero).

PROC SQL noprint;
      CREATE TABLE check AS

            SELECT *, round(var1+var2,1e16) as final

            FROM dir.A;

QUIT;
Joe
  • 62,789
  • 6
  • 49
  • 67