In my code I am attempting to calculate the elapsed time between two time points (response time). I have formatted all of my time variables into the "time." format in SAS. In majority of cases, I am able to calculate a positive elapsed time by subtracting time point 2 from time point 1 (i.e. 19:24:01 - 19:19:22 = 0:04:39 = 4 minutes 39 seconds elapsed).
Although there is a select group of observations where the time window crossed 12am (i.e.<23:59:59 and >00:00:00). Using my method to calculate the elapsed time, I am getting negative elapsed time. For example the time interval between 11:58:35PM and 0:05:51AM is calculated as -23:52, when the true interval should be 0:07:16 (7 minutes 16 seconds).
Does anyone know of a simple way to correct these observations? See current simple SAS code below:
data datawithtime;
set rawdata;
elapsedtime=time2-time1;
run;