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,
You're running into numerical precision issues.
Round the value before comparison.
if round(tw_amount) = 0 then ...
Then round to the nearest cent...
round(variable, 0.01)
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.