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

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?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
mk131190
Obsidian | Level 7

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

 

ballardw
Super User

Consider

 

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

and

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 677 views
  • 0 likes
  • 3 in conversation