A_B_C,
I hadn't realised from your original post that you wanted that flexibility.
It's a simple step to put the code you require into a macro. For example:
data a;
input patid week day dose;
Infile cards;
cards;
1 1 1 10
1 1 3 11
1 2 1 12
1 2 3 13
1 3 1 13
1 4 1 14
1 5 1 15
1 5 3 16
1 6 1 17
1 6 3 18
;
run;
/* Now define the macro - note that timst and timend allow you to name the
start and stop months that you're interested in. */
%MACRO reread(track=,timst=,timend=,in=a,out=b);
DATA &out;
SET ∈
%DO i = &timst %TO %EVAL(&timend);
IF _n_ > &i THEN SET &in(KEEP = &track RENAME=(&track=&track.min&i));
%END;
RUN;
%MEND reread;
/* now - to track the variable dose for 2 to 3 months ago */
%reread(track=dose,timst=2,timend=3,in=a,out=b);
proc print data=b;
run;
/* the above print gives the following output. */
Obs patid week day dose dosemin2 dosemin3
1 1 1 1 10 . .
2 1 1 3 11 . .
3 1 2 1 12 10 .
4 1 2 3 13 11 10
5 1 3 1 13 12 11
6 1 4 1 14 13 12
7 1 5 1 15 13 13
8 1 5 3 16 14 13
9 1 6 1 17 15 14
10 1 6 3 18 16 15
Perhaps this is addresses your needs more accurately?
Regards,
BPD