Hi all, was wondering can I have a if statement, and then the program will run the if statement in it if the condition is fulfill with the first if statement?
Here's my code below., but this is not work
if ratecde^=1000 or ratecde^=coin or ratecde^= then
if test2=10 then
cov_type='MD1';
else if test2=11 then
cov_type='MD2';
else if test2=12 then
cov_type='MD3';
else if test2=14 then
cov_type='MD4';
else if test2=29 then
cov_type='MD5';
else
cov_type='MD6';
RUN;
if ratecde^=1000 or ratecde^=coin or ratecde^= then do;
if test2=10 then cov_type='MD1';
else if test2=11 then cov_type='MD2';
else if test2=12 then cov_type='MD3';
else if test2=14 then cov_type='MD4';
else if test2=29 then cov_type='MD5';
end;
else cov_type='MD6';
What does the log say?
if ratecde^=1000 or ratecde^=coin or ratecde^= then do;
if test2=10 then cov_type='MD1';
else if test2=11 then cov_type='MD2';
else if test2=12 then cov_type='MD3';
else if test2=14 then cov_type='MD4';
else if test2=29 then cov_type='MD5';
end;
else cov_type='MD6';
As shown by @PaigeMiller , you have to enclose the instructions following your fisrt if by do; ... end;
You can also avoid to use multiple if's by using a format :
proc format;
value cov
10="MD1"
11="MD2"
12="MD3"
14="MD4"
29="MD5"
other="MD6"
;
run;
data have;
do test2=10 to 30;
cov_type=put(test2,cov.);
output;
end;
run;
@Kayla_Tan222 wrote:
Hi all, was wondering can I have a if statement, and then the program will run the if statement in it if the condition is fulfill with the first if statement?
Hi @Kayla_Tan222,
Yes, you can, but the condition "ratecde^= " is incomplete: the "not equal" operator (^=) must be followed by a value, perhaps you mean a numeric missing value (denoted by a period) in this case: ratecde^=.
However, in this case and also with any other constant value (except 1000) that you might insert there, your initial IF condition would always be met (and hence be redundant) because ratecde cannot equal 1000 and the other value at the same time.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.