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
- /
- getting unintended output with zeros

- 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

11-09-2016 08:52 AM

I am using the below code, the intent is to verify that the sum/difference of three columns equals another column. I am not getting the intended output.

I also tried the commented line but got the same output:

data rules;

set other_data;

format delta value $20.;

if not missing(d_net_co) then do;

/*if D_NET_CO ne (D_GCO + D_BKCO - D_RECOVERIES) then*/

if D_NET_CO - (D_GCO + D_BKCO - D_RECOVERIES) ne 0 then

edit_67 = 1;end;

if edit_67 = 1;

Value = (D_GCO + D_BKCO - D_RECOVERIES);

Delta = value - d_net_co;

keep rssd_id segment_id d_net_co d_gco d_bkco d_recoveries value delta;

run;

Please find the attachment that shows the output.

Can someone help me understand why the delta column containing zero's are included with the output?

Accepted Solutions

Solution

11-09-2016
09:18 AM

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

Posted in reply to Steelers_In_DC

11-09-2016 09:10 AM

Numerical precision.

Computers can't store decimal numbers/fractions exactly.

Round your answer before comparison for deletion.

ROUND() function

All Replies

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

Posted in reply to Steelers_In_DC

11-09-2016 09:07 AM

Not sure I understand the issue, why would you not get records in your output with delta values of zero?

Solution

11-09-2016
09:18 AM

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

Posted in reply to Steelers_In_DC

11-09-2016 09:10 AM

Numerical precision.

Computers can't store decimal numbers/fractions exactly.

Round your answer before comparison for deletion.

ROUND() function

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

Posted in reply to Reeza

11-09-2016 09:15 AM

A requirement set by the fed for this field is that it it have 6 decimal places. Will the round function solve the issue rounding that far?

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

Posted in reply to Steelers_In_DC

11-09-2016 09:18 AM

Looks like it did, thanks!!

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

Posted in reply to Steelers_In_DC

11-09-2016 09:19 AM

The second parameter in ROUND function allows specification of precision.

Round(VAR, 0.000001) ;

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

Posted in reply to Reeza

11-09-2016 10:57 AM

Actually the SAS Round function has lots of fun possibilities. You can round to practically any multiple. So Round(value,7) or Round(value, 0.0006) are valid and round to the nearest multiple of 7 or 0.0006. I will admit that practical uses for rounding to 1.7 may be few and far between but when needed can save a LOT of possibly obnoxious code.

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

Posted in reply to ballardw

11-09-2016 11:00 AM

I've only ever used it to truncate what I needed, never thought of it to force a number longer. I guess it's nothing I've ever come across. Very useful. A nice tool to add to the toolbox.

Thanks!!