Solved
Valued Guide
Posts: 864

# getting unintended output with zeros

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
Super User
Posts: 23,770

## Re: getting unintended output with zeros

Numerical precision.

Computers can't store decimal numbers/fractions exactly.

http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t...

ROUND() function

All Replies
PROC Star
Posts: 1,283

## Re: getting unintended output with zeros

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
Super User
Posts: 23,770

## Re: getting unintended output with zeros

Numerical precision.

Computers can't store decimal numbers/fractions exactly.

http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t...

ROUND() function

Valued Guide
Posts: 864

## Re: getting unintended output with zeros

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?

Valued Guide
Posts: 864

## Re: getting unintended output with zeros

Looks like it did, thanks!!

Super User
Posts: 23,770

## Re: getting unintended output with zeros

The second parameter in ROUND function allows specification of precision.

Round(VAR, 0.000001) ;

Super User
Posts: 13,581

## Re: getting unintended output with zeros

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.

Valued Guide
Posts: 864

## Re: getting unintended output with zeros

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!!

☑ This topic is solved.