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.
CodePudding user response:
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.
from my_table;
quit;