I have tested the code with the sample data without any errors.
If you are trying to run the code with your actual data, you would need to make some modifications.
The number of array elements will be determined dynamically by the code below.
array dt[*] date1-date&max_ct.;
array time[*] time1-time&max_ct.;
See if this works, post the log if you get errrors.
proc sql noprint;
select strip(put(count(date),4.)) into :max_ct
from have
group by id;
quit;
%put *&max_ct.*;
data want;
array dt[*] date1-date&max_ct.;
array time[*] time1-time&max_ct.;
format date: first_enc_date date9.;
do i=1 by 1 until(last.id);
set have;
by id date;
dt[i]=date;
if first.id then do;
first_enc_date=date;
end;
end;
do i=1 to i;
set have;
do j = 1 to dim(dt)-1;
if dt[j] > 0 then time[j]=(dt[j+1] <= intnx('year',dt[j],2,'same'));
end;
output;
end;
drop i j date1-date&max_ct.;
run;
... View more