BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
HitmonTran
Pyrite | Level 9

hello,

 

I need to calculate the # mins from start and stop time; however, i have one subject with a special situation. 

 

Most subjects have start/stop time within the same day, but one subject (subject dd) has a stop time after midnight, which causes the calculation to be a negative number eg. 00:57 - 19:10 = -1093 mins.  How would I solve this issue?

 

 

data:

subjectstart time (time5. format)stop time (time5. format)
aa14:3514:02
bb10:46 
cc13:0511:37
dd00:5719:10

 

 

 

want:

subjectmins 
aa33
bb.
cc88
dd347
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

See if this gives you the desired result. Should be easy to follow

 

data have;
input subject $ (starttime stoptime)(:time5.);
infile datalines missover;
format starttime stoptime time5.;
datalines;
aa 14:02 14:35 
bb 10:46       
cc 11:37 13:05 
dd 19:10 00:57 
;

data want(drop = starttime stoptime);
   set have;
   
   if stoptime < starttime then stoptime = stoptime + 3600*24;

   mins = intck('minute', starttime, stoptime);
run;

 

Result:

 

subject  mins
aa       33
bb       .
cc       88
dd       347

 

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Shouldn't start and stop time be reversed? If starttime and stoptime is within the same day for subject = 'aa', then it can not start at 14:35 and stop at 14:02?

PeterClemmensen
Tourmaline | Level 20

See if this gives you the desired result. Should be easy to follow

 

data have;
input subject $ (starttime stoptime)(:time5.);
infile datalines missover;
format starttime stoptime time5.;
datalines;
aa 14:02 14:35 
bb 10:46       
cc 11:37 13:05 
dd 19:10 00:57 
;

data want(drop = starttime stoptime);
   set have;
   
   if stoptime < starttime then stoptime = stoptime + 3600*24;

   mins = intck('minute', starttime, stoptime);
run;

 

Result:

 

subject  mins
aa       33
bb       .
cc       88
dd       347

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1115 views
  • 0 likes
  • 2 in conversation