DateTime Threshold

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

DateTime Threshold

I am doing a case statement in SAS and want all date time variables below dd-mmm-yyyy 08:00:00 to have time set as 08:00:00 for one day and 09:00:00 for another day.

 

Is there an easy way to do this?

 

 


Accepted Solutions
Solution
‎04-04-2016 06:43 AM
Super User
Super User
Posts: 7,686

Re: DateTime Threshold

Well, I have noting to work with here, but at a guess:

proc sql;
  create table WANT as
  select   case when timepart(DATETIME_VAR) < "08:00"t then 
                        input(put(datepart(DATETIME_VAR)||"T08:00:00",datetime.)
                     else DATETIME_VAR as RESULT format=datetime.
  from     HAVE;
quit;

View solution in original post


All Replies
Solution
‎04-04-2016 06:43 AM
Super User
Super User
Posts: 7,686

Re: DateTime Threshold

Well, I have noting to work with here, but at a guess:

proc sql;
  create table WANT as
  select   case when timepart(DATETIME_VAR) < "08:00"t then 
                        input(put(datepart(DATETIME_VAR)||"T08:00:00",datetime.)
                     else DATETIME_VAR as RESULT format=datetime.
  from     HAVE;
quit;
Occasional Contributor
Posts: 19

Re: DateTime Threshold

[ Edited ]

Sorry further understanding below.

 

CASE WHEN timepart(a.date) < '08:00:00't AND put(a.date,weekdate3.) IN ('MON','TUE','WED','THU','FRI')
THEN 

 

 WHEN timepart(a.date) < 09:00:00't AND put(a.date,weekdate3.) = 'SAT' 

THEN 

 

WHEN timepart(a.date) < 10:00:00't AND put(a.date,weekdate3.) = 'SUN' 
THEN 


ELSE date
END AS date2

Super User
Super User
Posts: 7,686

Re: DateTime Threshold

You already have all the code there, just put it together:

 

case when timepart(a.date) < '08:00:00't and put(a.date,weekdate3.) in ('MON','TUE','WED','THU','FRI')
then input(put(datepart(DATETIME_VAR)||"T08:00:00",datetime.)
when ...
else ... end as DATE2

 

Super User
Posts: 11,105

Re: DateTime Threshold

Consider

 

Weekday(a.date) in (2:6)

and

Weekday(a.date) = 1 (sunday) or 7 (saturday)

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 331 views
  • 0 likes
  • 3 in conversation