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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.