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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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