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

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Comparing Numberic Values

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
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-14-2010 08:23 AM

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?

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?

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

04-14-2010 01:50 PM

Hi,

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,

Florent

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,

Florent

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

04-14-2010 02:04 PM

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

lagbal*-1

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.

lagbal*-1

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.