Hi I would like to know the steps of a multiple if then condition.
I would like to do the following:
data _ ;
set _ ;
if condition 1 is true then do;
if sub condition 1 is true then _ ;
else if sub condition2 is true then _;
else if ... ;
end;
else if condition 2 is true then do; /* Is it right? */
if sub condition 1 is true then _ ;
else if sub condition2 is true then _;
else if ... ;
end;
run;
Could you please tell me which the right steps are? I should include else if or else do?
For example: condition 1 can take values 1 or 0. sub-conditions (I will call them as test1,test2, test3, ...) are other conditions. So I would have something like :
data _ ;
set _ ;
if condition1 = 1 then do;
if test1 = . then test3=test2; else test3=test1;
else if test1 = 'My test' or test2= 'My test' then test3=test2 else test3=test2;
end;
else if condition1=0 then do;
if test1 = . then test3=test2; else test3=test1;
else if test1 = 'My test' or test2= 'My test' then test3=test2 else test3=test2;
end;
else test3=test2;
run;
A sample of data could be:
condition1 test1 test2
1 . M
0 My test .
1 Love home
0 Home .
what I would like to select is, based on condition1 values,
if condition1 is 1 and test1 is . then assign to test3 test2's value, otherwise test3=test1; and so on.
My expected output would be then:
condition1 test1 test2 test3
1 . M M
0 My test . My test
1 Love home Love
0 Home . Home
test1 = ., and in other places as character,test1 = 'My test'. You can use themissing()function to test if a variable is missing and it will work the same for numeric or character variables, plus it will detect special missing values like.A,.Zetc. - Tom