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
- /
- Base SAS Programming
- /
- question related to LE operator

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

12-27-2016 02:28 PM

Hi,

I am trying to run the below code.

**data** one;

input a b;

datalines;

12.45 12.40

13.55 13.50

17.50 17.45

14.70 14.76

15.47 15.50

;

**run**;

**data** two;

set one;

diff1= abs(b-a);

if abs(b-a) le **0.05** then result='success';

else result='failure';

**run**;

The second and third row has diff1 equal to 0.05 but the result is getting value failure. First row is getting values appropriately.

Appreciate any help.

Regards,

Sheeba

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

12-27-2016 03:56 PM

Round the numbers before you do a calculation.

Numbers cannot be stored exactly so the number is likely 0.050000001 or something like that.

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

12-28-2016 12:57 PM

Hi Reeza,

Thanks a lot for the details.

It is working as expected now

Regards,

Sheeba

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

12-27-2016 04:23 PM

As @Reeza wrote: It's about rounding and how computers store values.

Run below code and have a look at the "data two"

```
data one;
input a b;
datalines;
12.45 12.40
13.55 13.50
17.50 17.45
14.70 14.76
15.47 15.50
;
run;
data two;
set one;
format diff1 diff2 best32.;
diff1= abs(b-a);
diff2=round(diff1,0.000001);
if round(abs(b-a),0.0000001) le 0.05 then
result='success';
else result='failure';
run;
```

It's not so that SAS does something wrong but it is a common trap and I'd wish for some system option which would allow us to define a max. precision so that rounding happens implicitely.

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

12-28-2016 03:56 AM

Hello,

I totally agree with @Patrick ' s proposal about the rounding . I have met many people working with SAS failing to deal properly with number calculation.

If I may , I would add a note in the log specifying the implicit rounding (when it takes place).

@Patrick could you open a topic so the community votes for this proposal ?

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

12-28-2016 01:02 PM

Hi Loko,

Thanks for the reply. Yes rounding resolved the issue here

Regards,

Sheeba

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

12-28-2016 01:00 PM

Hi Patrick,

Thanks for helping me out. With rounding the issue is resolved.

The option to define a max precision will be nice to have in such cases .

Thanks again,

Regards,

Sheeba