DATA Step, Macro, Functions and more

getting unintended output with zeros

Accepted Solution Solved
Reply
Valued Guide
Posts: 860
Accepted Solution

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: 19,772

Re: getting unintended output with zeros

Posted in reply to Steelers_In_DC

 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 your answer before comparison for deletion. 

 

 

ROUND() function 

View solution in original post


All Replies
PROC Star
Posts: 734

Re: getting unintended output with zeros

Posted in reply to Steelers_In_DC

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

Solution
‎11-09-2016 09:18 AM
Super User
Posts: 19,772

Re: getting unintended output with zeros

Posted in reply to Steelers_In_DC

 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 your answer before comparison for deletion. 

 

 

ROUND() function 

Valued Guide
Posts: 860

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: 860

Re: getting unintended output with zeros

Posted in reply to Steelers_In_DC

Looks like it did, thanks!!

Super User
Posts: 19,772

Re: getting unintended output with zeros

Posted in reply to Steelers_In_DC

The second parameter in ROUND function allows specification of precision. 

 

Round(VAR, 0.000001) ;

Super User
Posts: 11,343

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: 860

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 353 views
  • 0 likes
  • 4 in conversation