I have a table with 2 columns, I need to update one of them based on values in another.
Column A is a flag (1s and 0s), column B is a string column. I need update column B based on the flag in column A. If A = 1 then column B needs to preserve its values, if column A is 0, I need to set column B to blank.
column A. Column B.
1 abc <-keep
0 abc <-set to blank
1 abc <-keep
PROC SQL;
update table abc
set column B =
case when A.column IS NOT NULL then A.column = A.column
else A.column = ' '
end
>Solution :
Simply using Update with CASE statement to do what you want:
update column B based on the flag in column A. If A = 1 then column B
needs to preserve its values, if column A is 0, I need to set column B
to blank.
UPDATE
your_table
SET
column_B = CASE
WHEN column_A = 1 THEN column_B -- columnB needs to preserve its value
ELSE '' -- set column B to blank.
END;
Before:
column_A column_B
1 abc
0 abc
1 abc
After update:
column_A column_B
1 abc
0
1 abc