Hi all,
I have longitudinal data (1 obs per person per minute) with two time variables: date and time. I would like to create summary variables between 7pm on one day and 12 pm on the next day. How can I create this time interval using these two variables???
Thanks!
On second thought, not sure it matters either. Try this:
data want;
set have;
if hour(timepart(datetime)) >= 19 or hour(timepart(datetime)) <= 12 then interval='Night';
else interval = 'Day';
run;
I combined date and time into one variable. I'd still only like to count people between certain time intervals.
data WORK.CLASS;
infile datalines truncover;
input Name:$8. sleep datetime;
informat datetime datetime20.;
format datetime datetime20.;
datalines;
Alfred 0 04MAR14:23:55:00
Alfred 0 04MAR14:23:56:00
Alfred 1 04MAR14:23:57:00
Alfred 1 04MAR14:23:58:00
Alfred 1 04MAR14:23:59:00
Alfred 1 04MAR14:00:00:00
Alfred 1 04MAR14:01:01:00
Alfred 1 04MAR14:01:02:00
Alfred 1 04MAR14:01:03:00
Alfred 1 04MAR14:01:04:00
mary 0 04MAR14:23:55:00
mary 0 04MAR14:23:56:00
mary 1 04MAR14:23:57:00
mary 1 04MAR14:23:58:00
mary 1 04MAR14:23:59:00
mary 1 04MAR14:00:00:00
mary 1 04MAR14:01:01:00
mary 1 04MAR14:01:02:00
mary 1 04MAR14:01:03:00
mary 1 04MAR14:01:04:00
;
I have one week per person, every single minute!
I understand that, but is there a starting date and end date that you know, ie the data is all between 2014 and 2018?
@lalaktgrau wrote:
I have one week per person, every single minute!
No! It's all over the place. Different people had different starts and ends. I just want to pull all the nighttime data, so I think we can disregard the dates (except to know start of night one day, morning the next day 7pm-12pm).
On second thought, not sure it matters either. Try this:
data want;
set have;
if hour(timepart(datetime)) >= 19 or hour(timepart(datetime)) <= 12 then interval='Night';
else interval = 'Day';
run;
Hello, can you explicitly specify your output ? if possible.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.