Hi @NewUsrStat, here's some code that will get the job done but I should mention it's convoluted and makes a few assumptions which may or may not work in all situations.
data db_temp;
retain max_index;
set db;
by id;
if first.id then max_index=0;
max_index=max(max_index,index);
if last.id;
keep id max_index;
run;
data db1;
merge db db_temp;
by id;
if event=1 then index=max_index;
else if index=max_index then index=0;
run;
Happy to iterate if you can provide more information about whether each ID will have at least one observation where event=1, whether max(index) is what we're looking for, ...
... View more