Hi Channel,
I have "IF else" statement which I want to convert to "case when" could you please help .
IF Rate "" THEN DO ;
A ="LIGHT"; B =1;
IF HIGH =1 THEN DO;
U = A1 ;
V = 1;
W = 1;
X = A1_PO;
Y = 1;
Z = 1;
END;
IF HIGH =2 THEN DO;
U = 1;
V = A1 ;
W = 1;
X = 1;
Y = A1_PO;
Z = 1;
END;
IF HIGH =3 THEN DO;
U = 1;
V = 1;
W = A1 ;
X = 1;
Y = 1;
Z = A1_PO;
END;
END;
ELSE IF AMOUNT 1 NE AMOUNT 2 THEN DO;
A ="HARD"; B =2;
IF HIGH =1 THEN DO;
U = APPLE;
V = 1;
W = 1;
X = APPLE_GREEN;
Y = 1;
Z = 1;
END;
IF HIGH =2 THEN DO;
U = 1;
V = APPLE;
W = 1;
X = 1;
Y = APPLE_GREEN;
Z = 1;
END;
IF HIGH =3 THEN DO;
U = 1;
V = 1;
W = APPLE;
X = 1;
Y = 1;
Z = APPLE_GREEN;
END;
END;
ELSE DO ;
A = "SOFT" ; B =3;
IF HIGH =1 THEN DO;
U = ORANGE;
V = 1;
W = 1;
X = ORANGE_TANGY;
Y = 1;
Z = 1;
END;
IF HIGH =2 THEN DO;
U = 1;
V = ORANGE;
W = 1;
X = 1;
Y = ORANGE_TANGY;
Z = 1;
END;
IF HIGH =3 THEN DO;
U = 1;
V = 1;
W = ORANGE;
X = 1;
Y = 1;
Z = ORANGE_TANGY;
END;
END;
I have converted all but can't able fit all under ELSE.
Please help and I want to use sql "case when" because I want to migrate this to angular SQL so can't use data step
In SQL you will need to redo the logic so that it calculates each output variable independently. You appear at first glance to have output variables of A,B,U, V, W, X, Y and Z so you will need 8 CASE .... END clause in your SQL select statement.
Show us the case-when expression you have for, say, U.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.