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
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;
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;
Thank you
Kindly close the thread by marking the reply as "Accepted Solution"
@podarum Please mark the question answered.
@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!
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.
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
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.