Help using Base SAS procedures

Comparing Numberic Values

Occasional Contributor
Posts: 18

Comparing Numberic Values

I have an issue and have tried various ways of using the ROUND() function, but it's still not giving me what I need.

Here is the example:

bal lagbal lagbal2
1119.16 -847.64 271.52

The line in the program for the data above is:

if bal=((lagbal*-1)+lagbal2) then paid=0

if I change it to:
if bal ne ((lagbal*-1)+lagbal2) then paid=0
then it works

When I compare the value of the bal and the expression (lagbal*-1)+lagbal2 then I get an exponential number. I have tried to round the variables, and it works for some but not all. Any ideas on what I can do?
Frequent Contributor
Posts: 127

Re: Comparing Numberic Values


I faced the same kind of issue and fixed it by forcing SAS to make the automatic conversion to a numeric variable.

In your example, it becomes:

if bal= put(((lagbal*-1)+lagbal2), best32.) then paid=0;

I don't know what really is the problem with SAS (we are still using the version 8) for such a situation and even don't know whether there is a fix to apply in order not having to implement such crappy solutions...

Kind regards,
Valued Guide
Posts: 2,108

Re: Comparing Numberic Values

I'm not sure what you are trying to do, but I suspect that the problem is in


Because you didn't use parentheses, SAS has to make a guess about whether the minus sign is subtraction or an infix operator. The multiplication can cause roundoff error (remember that the arithmetic is done in base-2) that makes the equal sign fail.

Does it work if you re-write as

IF bal=(labgal2 - lagbal) THEN paid=0; ?

Subtraction induces less roundoff error than multiplication.
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation