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

I have the following code that I am working with:

data waiver2(keep=pidm_key tw_amount tbraccd_detail_code tbraccd_term_code);
retain tw_amount;
set waiver;
by pidm_key tbraccd_detail_code tbraccd_term_code;
if first.tbraccd_term_code then tw_amount=0;
tw_amount + tbraccd_amt;
if last.tbraccd_term_code;
if tw_amount>= 0.01;
run;

 

The data that I have when I go into the tw_amount + tbraccd_amt is:

tw_amount = 464
pidm_key = 233793
tbraccd_amt = -464
TBRACCD_DETAIL_CODE = WFOS
TBBDETC_DESC = Waiver CR: MD Foster Care
TBRACCD_TERM_CODE = 201540
FIRST.pidm_key = 0
LAST.pidm_key = 1
FIRST.TBRACCD_DETAIL_CODE = 0
LAST.TBRACCD_DETAIL_CODE = 1
FIRST.TBRACCD_TERM_CODE = 0
LAST.TBRACCD_TERM_CODE = 1

 

After the addition my data looks like this:

tw_amount = -5.6843418860808E-14
pidm_key = 233793
tbraccd_amt = -464
TBRACCD_DETAIL_CODE = WFOS
TBBDETC_DESC = Waiver CR: MD Foster Care
TBRACCD_TERM_CODE = 201540
FIRST.pidm_key = 0
LAST.pidm_key = 1
FIRST.TBRACCD_DETAIL_CODE = 0
LAST.TBRACCD_DETAIL_CODE = 1
FIRST.TBRACCD_TERM_CODE = 0
LAST.TBRACCD_TERM_CODE = 1

 

What is going on & how can I avoid this as I want to change the last if statement to not = 0?

 

Thank you,

1 ACCEPTED SOLUTION

Accepted Solutions
3 REPLIES 3
Reeza
Super User

You're running into numerical precision issues. 

Round the value before comparison.

 

if round(tw_amount) = 0 then ...

HarfordKaren
Calcite | Level 5
The number is a dollar amount so if I round it I will lose the cents. How do I deal with that?
Reeza
Super User

Then round to the nearest cent...

 

round(variable, 0.01)

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1045 views
  • 0 likes
  • 2 in conversation