Multiple conditions in one if statement

Accepted Solution Solved
Reply
Super Contributor
Posts: 396
Accepted Solution

Multiple conditions in one if statement

[ Edited ]

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

 

 

 


Accepted Solutions
Solution
‎01-30-2016 10:34 PM
Super Contributor
Posts: 490

Re: Multiple conditions in one if statement

[ Edited ]

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


All Replies
Solution
‎01-30-2016 10:34 PM
Super Contributor
Posts: 490

Re: Multiple conditions in one if statement

[ Edited ]

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;

 

Super Contributor
Posts: 490

Re: Multiple conditions in one if statement

Super Contributor
Posts: 396

Re: Multiple conditions in one if statement

Thank you

Super Contributor
Posts: 490

Re: Multiple conditions in one if statement

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

Super User
Posts: 17,963

Re: Multiple conditions in one if statement

@podarum Please mark the question answered.

Contributor
Posts: 22

Re: Multiple conditions in one if statement

@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!

Super Contributor
Posts: 490

Re: Multiple conditions in one if statement

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.

Contributor
Posts: 46

Re: Multiple conditions in one if statement

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

 

 

Super User
Posts: 17,963

Re: Multiple conditions in one if statement

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;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 649 views
  • 1 like
  • 5 in conversation