Hello @kashlik123,
The date sequences in your sample data have no gaps (of >=2 days) and no duplicates within an ID. My suggested DATA step below only assumes the latter. If there are also no gaps in your real data, the code can be simplified. (Maybe you could handle duplicate dates, if any, in a preliminary PROC SUMMARY step aggregating var values by ID dt. But this depends on how you'd define the means in the presence of duplicate dates.)
data want(drop=_:);
array _3d[0:2] _temporary_;
array _6d[0:5] _temporary_;
set have_fin;
by id dt;
_d=dif(dt);
if first.id | _d>=6 then call missing(of _3d[*], of _6d[*], _i3, _i6);
else do;
do _j=1 to _d-1;
_i6+1;
_6d[mod(_i6,6)]=.;
end;
if _d>=3 then call missing(of _3d[*], _i3);
else do _j=1 to _d-1;
_i3+1;
_3d[mod(_i3,3)]=.;
end;
end;
_i3+1;
_i6+1;
_3d[mod(_i3,3)]=var;
_6d[mod(_i6,6)]=var;
mean_var_3d=mean(of _3d[*]);
mean_var_6d=mean(of _6d[*]);
run;
... View more