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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 853 views
  • 0 likes
  • 2 in conversation