Desktop productivity for business analysts and programmers

Date field - creating

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

Date field - creating

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


Accepted Solutions
Solution
‎09-25-2015 06:23 AM
Contributor
Posts: 41

Re: Date field - creating

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


All Replies
Super User
Super User
Posts: 6,364

Re: Date field - creating

[ Edited ]

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
;

 

Solution
‎09-25-2015 06:23 AM
Contributor
Posts: 41

Re: Date field - creating

Problem - the date returned is today's date. Statement:
CASE WHEN t1.SCHOOL_YEAR_ID = 18 THEN DATETIME('01MAY2015:00:00:00'DT)
END
Super User
Super User
Posts: 6,364

Re: Date field - creating

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

Contributor
Posts: 41

Re: Date field - creating

Oops. Removed my DATETIME and reran. Thanks Tom.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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