@ilikesas: If you do not have any missing dates in your table, you can calculate the standard deviation for 1461 days, (4 years exactly, unless you are around year 1900 or 2100) like this: data want;
set have;
by id;
array values(0:1460) 8 _temporary_;
if first.id then
call missing(of values(*));
values(mod(_N_,1461))=x;
if flag=1 then
rolling_std=std(of values(*));
run; If some days are missing in your table, it becomes more complicated. One way is to use SET with POINT= to find the values that you want to delete from the array: data want;
set have;
by id;
array values(0:1460) 8 _temporary_;
if first.id then do;
call missing(of values(*));
_p_first=_N_;
_date_first=date;
retain _p_first _date_first;
drop _p_first _date_first;
end;
values(mod(_N_,1461))=x;
do while(_date_first<date-1460);
_p_first+1;
set have(keep=date rename=(date=_date_first)) point=_p_first;
call missing(values(mod(_p_first,1461)));
end;
if flag=1 then
rolling_std=std(of values(*));
run;
Notice that I zero-based the array so that the MOD function can be used to calculate an index directly. While this approach may be a bit slower than calculating the sum, N, and sum-of-squares, it is also a lot simpler.
... View more