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

I'm writing my code wrong or I'm misunderstanding the order of operations. 

 

My Comp_Stnd_DVLD_Rate is coming back as .02 but it should be returning .04 (highlighted in red below).  SAS runs up against the first if/do and assigns the .02 but why is it not being reset to .04 when it runs up against a subsequent if/do?  Do I need to break it out into multiple statements and take a max?

 

COMB_Prem_current = $449,000

COMB_LOC_Current = 84

 

 

data brokers_tot_stnd_new2;
set brokers_tot_stnd_new1;
if (COMB_Prem_current <= 74999.99 and COMB_LOC_Current <= 9) then
do;
Comp_Stnd_DVLD_Rate = 0;
Comp_Stnd_DENASO_Rate = 0;
Comp_Stnd_VISASO_Rate = 0;
end;
else if ((75000.00 <= COMB_Prem_current <= 249999.99) and (10 <= COMB_LOC_Current <= 19)) then
do;
Comp_Stnd_DVLD_Rate = 0.01;
Comp_Stnd_DENASO_Rate = 1.20;
Comp_Stnd_VISASO_Rate = 1;
end;
else if ((250000.00 <= COMB_Prem_current <= 749999.99) or (20 <= COMB_LOC_Current <= 29)) then
do;
Comp_Stnd_DVLD_Rate = 0.02;
Comp_Stnd_DENASO_Rate = 1.20;
Comp_Stnd_VISASO_Rate = 1;
end;
else if ((750000.00 <= COMB_Prem_current <= 1499999.99) or (30 <= COMB_LOC_Current <= 39)) then
do;
Comp_Stnd_DVLD_Rate = 0.025;
Comp_Stnd_DENASO_Rate = 1.20;
Comp_Stnd_VISASO_Rate = 1;
end;
else if ((1500000.00 <= COMB_Prem_current <= 1999999.99) or (40 <= COMB_LOC_Current <= 49)) then
do;
Comp_Stnd_DVLD_Rate = 0.03;
Comp_Stnd_DENASO_Rate = 1.20;
Comp_Stnd_VISASO_Rate = 1;
end;
else if ((COMB_Prem_current >= 3000000.00) or (COMB_LOC_Current >= 50)) then
do;
Comp_Stnd_DVLD_Rate = 0.04;
Comp_Stnd_DENASO_Rate = 1.20;
Comp_Stnd_VISASO_Rate = 1;
end;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

How could it. You structured you conditional logic as one long IF/ELSE IF/ELSE IF ... series. Once it meets the condition of any of the IF conditions is will not then also go down the ELSE clause.

If you want the one that sets the value to 0.04 to override the test that results in  0.02 then change the order.

If you want each test to be evaluated independently then remove the ELSE keywords.   But then again the last true condition will "win".

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

How could it. You structured you conditional logic as one long IF/ELSE IF/ELSE IF ... series. Once it meets the condition of any of the IF conditions is will not then also go down the ELSE clause.

If you want the one that sets the value to 0.04 to override the test that results in  0.02 then change the order.

If you want each test to be evaluated independently then remove the ELSE keywords.   But then again the last true condition will "win".

 

LuAnnS
Fluorite | Level 6

I see what you're saying.  Thank you.  As soon as I took out the 'else', it worked.  

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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