BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
carmendee
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
carmendee
Obsidian | Level 7
Problem - the date returned is today's date. Statement:
CASE WHEN t1.SCHOOL_YEAR_ID = 18 THEN DATETIME('01MAY2015:00:00:00'DT)
END

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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
;

 

carmendee
Obsidian | Level 7
Problem - the date returned is today's date. Statement:
CASE WHEN t1.SCHOOL_YEAR_ID = 18 THEN DATETIME('01MAY2015:00:00:00'DT)
END
Tom
Super User Tom
Super User

DATETIME() function just returns the current date time.  Use just the literal or another function such as INPUTN().

carmendee
Obsidian | Level 7
Oops. Removed my DATETIME and reran. Thanks Tom.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1901 views
  • 0 likes
  • 2 in conversation