data modify;
set have;
/* Determine if start to end time crosses 30 minute boundary */
start_period=round(tsp_start-900,1800);
end_period=round(tsp_end-900,1800);
/* If start_period < end_period then we need to split the row into two or more rows */
if start_period < end_period then do;
delta=floor(end_period-start_period)/1800;
do i=0 to delta;
duration=(min(end_period,tsp_end)-tsp_start);
output;
start_period=start_period+1800;
tsp_start=end_period;
end_period=end_period+1800;
end;
end;
else do;
duration=tsp_end-tsp_start;
output;
end;
format start_period end_period datetime18. duration time.;
drop i;
run;
proc summary data=modify nway;
class start_period status;
var duration;
output out=want sum=;
run;
... View more