Good day,

I have two variables (among others): One variable is a binary variable 0 or 1 (sleepwake). The other variable (datetime) is date followed by time (in %tc format). There are 7 days worth of rows, at 15-sec intervals. I want to create a new variable, called "sri", and I want to replace sri for datetime with 0 if sleepwake at datetime != sleepwake at datetime + 24 hours, and I want to replace sri for datetime with 1 if sleepwake at datetime == sleepwake at datetime + 24h. sri for the last day must be "." since there is no sleepwake for datetime + 24 hours to compare with.

datetime sleepwake sri
24feb2017 18:01:30 0 0
24feb2017 18:01:45 0 1
24feb2017 18:02:00 0 1
24feb2017 18:02:15 1 1
24feb2017 18:02:30 1 1
...
25feb2017 18:01:30 1 .
25feb2017 18:01:45 0 .
25feb2017 18:02:00 0 .
25feb2017 18:02:15 1 .
25feb2017 18:02:30 1 .

Please help me find a solution.

Thanks so much.