## Working with military time

Solved
Occasional Contributor
Posts: 13

# 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
Super User
Posts: 10,761

## 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;``````

All Replies
Solution
‎12-09-2016 01:07 AM
Super User
Posts: 10,761

## 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.

Super User
Posts: 10,761

## 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 ``````
Super User
Posts: 23,662

## Re: Working with military time

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

Super User
Posts: 23,662

## 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.