I would like to use first. and last. with an array statement. It should work like this: data have;
informat date mmddyy8.;
format date date9.;
input dose id $ supply date ;
datalines;
5 1234 30 01012015
10 1234 30 02012015
10 1234 30 03012015
5 1234 30 04012015
2 1234 30 05012015
5 4321 30 07012016
2 9876 30 05012016
2 9876 30 06012016
10 9876 30 07012016
;
run;
proc sort data=have;
by id date;
run;
data want;
set have;
by id dose notsorted;
retain n_days;
array my_array[*] dose id; do i=1 to dim(my_array);
if first.myarray(i)then n_days=0;
end;
n_days+supply;
if last.dose then output;
run; Since the real array contains more than 200 variables it is not possible to do this manually.
... View more