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

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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