How do I create a date field with a value using a CASE WHEN statement? Here is my statement:
CASE WHEN t1.year = 24 then '01MAY2015:00:00:00'
END
You probably want to use a date (or as in your example a datetime) literal. If you want a DATE then use '01MAY2015'D if you want a DATETIME value then use '01MAY2015:00:00:00'DT. You could also use a function call such as MDY(5,1,2015). You should also attach a format to the variable so the value will be displayed properly.
PROC SQL;
CREATE TABLE WANT AS
SELECT *
, CASE WHEN t1.year = 24 THEN '01MAY2015:00:00:00'dt
END AS DATETIME FORMAT=DATETIME20.
FROM HAVE
;
DATETIME() function just returns the current date time. Use just the literal or another function such as INPUTN().
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.