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

Hi,

How can I create multiple conditions form one if statement?

Here's what I mean.  The regular IF/THEN/ELSE statement is:

if product in ('ABC', 'CDE') THEN Var1=balance ; ELSE Var1=limit;  

 

What if I want to also apply Var2 and Var3?

 

So something like :

if product in ('ABC', 'CDE') THEN Var1=balance AND Var2=balance2 ; ELSE Var1=limit AND Var2=limit2;  

 

Thanks

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
mohamed_zaki
Barite | Level 11

I think the title is not matching the decriptions. You are asking about multiple actions not multiple coonditions. 

For applying multiple actions use Do; END;

like

if product in ('ABC', 'CDE') THEN Do;
    Var1=balance;
    Var2=balance2 ; 
END;
ELSE  Do;
	Var1=limit;
	Var2=limit2;  
END;

 

View solution in original post

9 REPLIES 9
mohamed_zaki
Barite | Level 11

I think the title is not matching the decriptions. You are asking about multiple actions not multiple coonditions. 

For applying multiple actions use Do; END;

like

if product in ('ABC', 'CDE') THEN Do;
    Var1=balance;
    Var2=balance2 ; 
END;
ELSE  Do;
	Var1=limit;
	Var2=limit2;  
END;

 

podarum
Quartz | Level 8

Thank you

mohamed_zaki
Barite | Level 11

Kindly close the thread by marking the reply as "Accepted Solution"

Reeza
Super User

@podarum Please mark the question answered.

chelsealutz
Fluorite | Level 6

@mohamed_zaki Would you please be able to tell me how to do multiple conditions in one If-Then statement? (I, too, was fooled by the title of this thread). 

 

I am trying:

if (opv0_card='Yes') & (opv0_recall=. or 'Yes') then opv0=1;
else if (opv0_card=.) & (opv0_recall='Yes') then opv0=2;
else opv0=3;

 

But unfortunately none of my '3' values are showing up, and way too many are being sorted into my '2' values... I would really appreciate your help! Thanks!

mohamed_zaki
Barite | Level 11

Your code should work. It may be other thing in your full code or with the data. I suggest you open new thread and post sample data with your full code. Then we could be more helpful.

Malathi13
Obsidian | Level 7

Hi,

I'm writing multiple conditions in if statement and I keep getting the same error that "Variable is uninitialized". can you please help me with the correct way of writing the if statement for multiple conditions. For e.g.

 

data new;

set have; 

if target=1 and Tier="D" or Tier in ("A", "B", "C") then  do all_total=final_call end;

 else do target=1 and Tier="D" or Tier in ("A", "B", "C") then do all_SAMPLE=sig_sam end; 

 else do target=0 and Tier="D" or Tier="Z" then do all_W_SAMPLE=nontgt_sam end;

run;

 

Can I do the same using proc sql by joining two tables such as table_A and table_B? How can I do that?

 

The error message I get is "Variable Final_call is uninitialized";

Variable sig_sam is uninitialized

variable nontgt_sam is uninitialized.

 

I used proc sql but it doesn't show any error messages but the dataset has zero observations.

 

Thank you

M

 

 

Reeza
Super User

Your problem is the DO THEN statements. 

If it's a single assignment you don't need DO THEN END. 

 

 

If <condition> then do;

sas code;

end;

else if ...

 

 

OR

 

if <condition> then all_toral=final_call;

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
  • 9 replies
  • 19376 views
  • 2 likes
  • 5 in conversation