You can take advantage of the fact that PROC SQL will automatically remerge summary statistics back with the detailed records to do this with a simple SQL query.
data have ;
input id year death;
cards;
1 2000 0
1 2002 0
1 2003 1
2 2000 0
2 2001 0
2 2002 0
3 2000 0
3 2002 0
3 2003 0
4 2001 0
4 2002 0
4 2003 1
5 2001 0
5 2003 0
;
proc sql ;
create table want as
select id
, year-min(year)+1 as time
, max(death) as death
, max(year)-min(year)+1 as studytime
from have
group by id
order by id, calculated time
;
quit;
Results
Obs id time death studytime
1 1 1 1 4
2 1 3 1 4
3 1 4 1 4
4 2 1 0 3
5 2 2 0 3
6 2 3 0 3
7 3 1 0 4
8 3 3 0 4
9 3 4 0 4
10 4 1 1 3
11 4 2 1 3
12 4 3 1 3
13 5 1 0 3
14 5 3 0 3