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