BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Steelers_In_DC
Barite | Level 11

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

 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

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

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

Reeza
Super User

 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 

Steelers_In_DC
Barite | Level 11

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?

Steelers_In_DC
Barite | Level 11

Looks like it did, thanks!!

Reeza
Super User

The second parameter in ROUND function allows specification of precision. 

 

Round(VAR, 0.000001) ;

ballardw
Super User

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.

Steelers_In_DC
Barite | Level 11

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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