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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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';

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
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';

--
Paige Miller
gamotte
Rhodochrosite | Level 12

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;
FreelanceReinh
Jade | Level 19

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

SAS Innovate 2025: Register Now

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!

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
  • 4 replies
  • 860 views
  • 1 like
  • 5 in conversation