Working with military time

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Working with military time

I am working with some sleep data and trying to calculate the difference between bedtime and wake-up time in military time in minutes using the intck function. When the bedtime is after midnight, this is pretty straightforward and SAS is giving me a correct value (for example, the difference between 00:20:00 and 07:30:00 is 430). However, it absolutely is not when the time is before 00:00. Does anyone have any ideas on how to fix this? Below is the code that I'm currently using.


data sds3;
set sds2;
tib=intck('minute',dsd_sleep_try,dsd_wake_time);
run;

 

Thanks


Accepted Solutions
Solution
‎12-09-2016 01:07 AM
Grand Advisor
Posts: 9,578

Re: Working with military time

data sds2;
dsd_sleep_try='00:20:00't;
dsd_wake_time='07:30:00't;
output;
dsd_sleep_try='23:30:00't;
dsd_wake_time='00:30:00't;
output;
format dsd_sleep_try dsd_wake_time tod10.;
run;
data sds3;
set sds2;
if dsd_sleep_try lt dsd_wake_time then 
 tib=intck('minute',dsd_sleep_try,dsd_wake_time);
else  tib=intck('minute',dsd_sleep_try,dsd_wake_time+'24:00:00't);
run;

View solution in original post


All Replies
Solution
‎12-09-2016 01:07 AM
Grand Advisor
Posts: 9,578

Re: Working with military time

data sds2;
dsd_sleep_try='00:20:00't;
dsd_wake_time='07:30:00't;
output;
dsd_sleep_try='23:30:00't;
dsd_wake_time='00:30:00't;
output;
format dsd_sleep_try dsd_wake_time tod10.;
run;
data sds3;
set sds2;
if dsd_sleep_try lt dsd_wake_time then 
 tib=intck('minute',dsd_sleep_try,dsd_wake_time);
else  tib=intck('minute',dsd_sleep_try,dsd_wake_time+'24:00:00't);
run;
Occasional Contributor
Posts: 13

Re: Working with military time

Magic. Thanks a ton.

Grand Advisor
Posts: 9,578

Re: Working with military time

I just realize if you have ties,maybe you need LE.

if dsd_sleep_try lt dsd_wake_time then 

---->
if dsd_sleep_try le dsd_wake_time then 
Grand Advisor
Posts: 17,345

Re: Working with military time

It's not likely but is possible to sleep more than 24 hrs. 

Grand Advisor
Posts: 17,345

Re: Working with military time

Your time components need a date, othwise how does the computer know that 23:30 is the previous day? 

 

If you have a date adding that that in is easiest using DHMS(). Also, you can subtract times directly without intck if that helps. 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 196 views
  • 3 likes
  • 3 in conversation