data want;
if _n_=1 then do;
dcl hash H () ;
h.definekey ("start_date_time") ;
h.definedata ("new_stop_date") ;
h.definedone () ;
end;
do _n_=1 by 1 until(last.id);
set have ;
by id;
if stop_date_time then _s=stop_date_time;
if method=2 then do;
_iorc_+1;
_k=lag(start_date_time);
if _iorc_>1 then h.add(key:_k,data:start_date_time);
end;
end;
do _n_=1 to _n_;
set have;
if method ne 2 then call missing(new_stop_date);
else if h.find() ne 0 then new_stop_date=ifn(_s,_s,static_date_time);
output;
end;
call missing(_iorc_);
h.clear();
format new_stop_date datetime20.;
drop _:;
run;
proc print noobs;run;
ID
method
start_date_time
static_date_time
stop_date_time
new_stop_date
1
1
01JAN19:11:13:00
11JAN19:15:12:00
.
.
1
2
01JAN19:12:15:00
11JAN19:15:12:00
.
02JAN2019:20:33:00
1
1
01JAN19:16:11:00
11JAN19:15:12:00
.
.
1
1
02JAN19:18:11:00
11JAN19:15:12:00
.
.
1
2
02JAN19:20:33:00
11JAN19:15:12:00
.
04JAN2019:21:12:00
1
1
03JAN19:12:12:00
11JAN19:15:12:00
04JAN2019:21:12:00
.
2
1
01JAN19:11:13:00
11JAN19:15:12:00
.
.
2
2
01JAN19:12:15:00
11JAN19:15:12:00
.
02JAN2019:20:33:00
2
1
01JAN19:16:11:00
11JAN19:15:12:00
.
.
2
1
02JAN19:18:11:00
11JAN19:15:12:00
.
.
2
2
02JAN19:20:33:00
11JAN19:15:12:00
.
11JAN2019:15:12:00
2
1
03JAN19:12:12:00
11JAN19:15:12:00
.
.
... View more