data want;
array p{0:4} _temporary_;
set have;
by gvkey year;
if first.gvkey then do;
call missing(of p{*});
num_years=0;
end;
num_years+1;
p{mod(_n_,5)} = sale;
*if you only want to calculate this once you have 5 years of data;
if num_years>=5 then sale_std = std(of p(*));
*if not conditional remove the IF portion;
run;
I would probably recommend PROC EXPAND as it will deal with missing data and years better, however, here's a rough data step approach. You will need to tailor to deal with missing years/data if necessary.
... View more