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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 570 views
  • 1 like
  • 5 in conversation