SQL can do this: data example;
input id price;
datalines;
1 437.83
2 458.5
3 457
4 456.98
5 459.11
6 453.91
7 444.05
8 456.47
9 463.25
10 474
;
run;
%let lag=10 ;
proc sql;
create table want as
select *,(select sum(id*price)/sum(id) from example where id between a.id-&lag and a.id) as wma
from example as a;
quit;
Xia Keshan
... View more