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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.