Skip to content
Advertisement

SAS Case Statement – if this, then that . else leave as is

I have a column with some unwanted data “XX” and want to set them as 0. Otherwise, keep the column’s data as it is. Something similar to if columnA = “XX” then 0 Else columnA. I tried doing this using a proc SQL SAS step, but that did not work. So looking for the most efficient way of doing using SAS SQL. Thanks for any help.

if columnA = "XX" then 0 
Else columnA
End as columnA

Advertisement

Answer

It’s a CASE statement in SQL.

Case when columnA='XX' then '0'
     else columnA 
end as ColumnA_New

original code: Case when columnA=’XX’ then 0 else columnA end as ColumnA

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement