dingaro
dingaro

Reputation: 2342

How to create column with date type date9. using case when in SAS Enterprise Guide 8.2?

I have SAS Enterprise Guide 8.2 and I try to create new column (data type = date) using case when. My code is:

proc sql;
select 
col1
, case when (col2 between '01SEP2019'd and '15SEP2019'd) then '01AUG2020'
       when (col2 between '01SEP2019'd and '15SEP2019'd) then '01OCT2020'
  end as col3 format = date9.
from my_table;
quit;

Unfortunately, when I run my code I have error: "ERROR: Character expression requires a character format.

How can I modify my code so as to have new created col3 as date format in SAS Enterprise Guide 8.2.

Upvotes: 0

Views: 940

Answers (1)

Reeza
Reeza

Reputation: 21294

You're missing the d after the quotes to indicate a date literal. As posted, your WHEN statements condition are identical though, so only the first one will be applied.

proc sql;
select 
col1
, case when (col2 between '01SEP2019'd and '15SEP2019'd) then '01AUG2020'd
       when (col2 between '01SEP2020'd and '15SEP2019'd) then '01OCT2020'd
  end as col3 format = date9.
, input('12344', 8.) as number_col
from my_table;
quit;

Upvotes: 0

Related Questions