Home > Mobile >  IF THEN ELSE statement in SAS
IF THEN ELSE statement in SAS

Time:10-29

What is wrong with this code?

Data antibiotics; 
    set antibiotics; 
    weight2=(IF weight=999,THEN weight2=.); 
        else weight2 = weight; 
run;`

I'm trying to create a new variable for weight that accounts for missing data in SAS

CodePudding user response:

It's invalid code. if statements in SAS do not come after the = sign.

data antibiotics;
    set antibiotics;
    
    if(weight = 9999) then weight2 = .;
        else weight2 = weight;
run;

CodePudding user response:

If you are an Excel'ist, the IFN() function might be familiar construct to you

  weight2 = IFN ( weight=999 , . , weight ); 
  • Related