data a;
set temp;
do i=1 to d;
qs=qssj+i;
output;
format qs yymmdd10.;
end;
run;
data b(drop=i qs lag_qs d pk); set a; by pk notsorted;
lag_qs=lag(qs);
if first.pk then lag_qs=.;
else qssj=lag_qs;
format lag_qs yymmdd10.;
run;[/code:wwv7ackc]
the target dataset and your requirment(statement) is somehow confused, hard to follow.Please give us your target dataset exact the same as what you wanted.
i.e. qssj=2012-04-05, there are 2 records with the same qssj, however, qssj=2012-04-06, there is only 1 record, and the other was deleted in your target dataset.