I suppose I get the correct result. See the picture below and here is my method. Here test is the data you provided and just read them through a txt file into sas dataset. My logic is to sum the difs between visits and then add the age from the first id. data test;
infile test;
input id visit vdate age @@;
run;
proc sort data=test; by id vdate;run;
data want; set test;
by id vdate;
retain temp_age;
if first.id then n=1;else n+1;
lag_vdate=lag(vdate);
lag_age=lag(age);
***sum the diffs among visits;
dif=((vdate-lag_vdate)/365.25);
sum+dif;
***replace the first id;
if first.id then do;
age_new=age;
age_end=age;
age_start=age;
temp_age=age;
end;
***calculate new age;
age_new=temp_age+sum;
lag_age_new=lag(age_new);
***start and end;
if n >1 then do;
age_start=lag_age_new;
age_end=age_new;
end;
keep id vdate lag_vdate age lag_age age_new lag_age_new age_start age_end n dif sum temp_age;
run;
... View more