I am getting sleep times and converting them to minutes to then calculate the standard deviation between bedtimes on different days. The issue is that some days the bedtime is after midnight. I got it to work on R but need the SAS code.
install.packages("chron")
library(chron)
data <- read.table(text="
sleep_time wake_time
23:30:00 05:30:00
00:00:00 05:30:00
00:30:00 05:35:00
", header=T)
mean(times(data$wake_time))
mean(times(data$sleep_time))
wake<- times(data$wake_time)
sleep <- times(data$sleep_time)
times(mean(ifelse(sleep <wake, sleep+1, sleep)))
sd(ifelse(sleep < wake, sleep+1, sleep) * 24*60)
This code reproduces what you're doing in R, with the following points of attention:
ifnis the (numeric) SAS version ofifelse. The unit is seconds here, so we're adding 24 x 60 x 60 rather than 1 (day). There's many other ways to conditionally do this addition.PROC SQLhere but there's many other ways to get summary statistics.