1

I am wondering if it is possible to replace values in an existing variable in the same SELECT statement in SQL.

create table temp as
     select ID
            , DOB 
            , AGE
            , DISEASE_INDICATOR
            , case when DISEASE_INDICATOR = 'Y' then 1 else 0
            end as DISEASE_INDICATOR
     from my_table;
quit;

The error message I get is: "WARNING: Variable DISEASE_INDICATOR already exists on file WORK.TEMP"

Thanks in advance!

ble9245
  • 15
  • 4

1 Answers1

0

Just remove the previous column:

create table temp as
     select ID, DOB, AGE,
            (case when DISEASE_INDICATOR = 'Y' then 1 else 0 end) as DISEASE_INDICATOR
     from my_table;
quit;

Or give the columns different names:

create table temp as
     select ID, DOB, AGE,
            DISEASE_INDICATOR as DISEASE_INDICATOR_YN,
            (case when DISEASE_INDICATOR = 'Y' then 1 else 0 end) as DISEASE_INDICATOR_01
     from my_table;
quit;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786