Hello,
my code below works but how can I improve it?
Is the case syntax the best choice? Or should I use the IF statement?
PROC SQL;
UPDATE GRV_Export_Dummy D
SET 'PAY'n = (CASE
WHEN (SELECT 'EB'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1'
THEN 'EB/'
ELSE ''
END)
||
(CASE
WHEN (SELECT 'M01'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1'
THEN 'M/'
ELSE ''
END)
||
(CASE
WHEN (SELECT 'V01'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'V02'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'V03'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1'
THEN 'V/'
ELSE ''
END)
||
(CASE
WHEN (SELECT 'H01'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'H02'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'H03'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'H04'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'H05'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'H06'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1'
THEN 'H/'
ELSE ''
END)
||
(CASE
WHEN (SELECT 'J01'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'J02'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'J03'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'J04'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'J05'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'J06'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'J07'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'J08'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'J09'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'J10'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'J11'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1' &&
(SELECT 'J12'n FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR) = '1'
THEN 'J/'
ELSE ''
END)
WHERE D.GRV IN (SELECT V.VTGONR FROM SERVER.VIEW_TABLE V WHERE D.GRV = V.VTGONR);
QUIT;
Additional I don't know how can I use a "nested case"?
For example
IF V01 = 1 THEN V01
IF V02 = 1 THEN V02
IF V03 = 1 THEN V03
IF V01 & VO2 & VO3 = 1 THEN V
Thanks,
Sascha
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.