Вы вычисляете продолжительность пробега для position
.По мере прохождения данных вам нужно будет отслеживать position
и start
прогона.Отслеживание можно выполнить с помощью переменной retain
ed.
data want;
set have;
by patientid date time; * add date and time to by statement so an error will log if the data is not in the required order;
if first.patientid then do;
run_position = position;
run_start = dhms (date,0,0,0) + time;
retain run_position run_start;
end;
if position = run_position then do;
hours_duration = intck ('hour', run_start, dhms(date,0,0,0) + time, 'continuous');
end;
else do;
* new run start;
run_position = position;
run_start = dhms (date,0,0,0) + time;
hours_duration = 0;
end;
flag_ge2hr = hours_duration >= 2;
run;