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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 866 views
  • 0 likes
  • 2 in conversation