我自己的code还是用macro写的:
[code:2kf1l8pw]
data tempi5; run;
%macro movingstd;
%do i = 1 %to 359034;
%put &i;
data tempi;
set originalfile;
if _N_=&i;
run;
proc sql;
create table tempi2 as
select b.*
from tempi a, originalfile b
where a.name=b.name and b.date<a.date and b.date>=intnx('month', a.date, -1)
order by date;
quit;
proc means data=tempi2 noprint;
var cds;
output out=tempi3(drop=_type_ _freq_) std=volatility;
run;
ps,我只有windows单机版,没有server用。:(作者: shiyiming 时间: 2010-1-5 22:37 标题: Re: 数组计算moving std问题 [quote:2ekntwbj]不过我不知道最大是多少,因为我只要一个月之内的数据,一个月之内trading的次数是不一定的,有的可以非常多,有的可以非常少。如果设个大的数组,那么可能会包括到多于一个月的数据啊。[/quote:2ekntwbj]
[code:2ekntwbj]data _null_;
retain yy 0;
m = 0;
do until(last.permno);
set stock;
by permno;
m+1;
end;
if yy < m then yy = m;
call symput ('_dim', yy);
run;
%put &_dim
;[/code:2ekntwbj]
The above code gives you the dimension of the array used later on. You can define the array like
[code:2ekntwbj]array a(&_dim);[/code:2ekntwbj]
Again, I don't think the array will contain those values not belonged to.作者: shiyiming 时间: 2010-1-7 10:30 标题: Re: 数组计算moving std问题 没大看懂...... <!-- s:? --><img src="{SMILIES_PATH}/icon_confused.gif" alt=":?" title="Confused" /><!-- s:? -->
proc sql;
create table temp(drop=startdate) as
select *,(select std(ret)
from raw b
where b.permno=a.permno and
a.startdate<=b.date<a.date
) as std
from (select *,intnx('month',date,-1,'sameday') as startdate format yymmdd10.
from raw) a;
quit;[/code:1mxiazet]作者: shiyiming 时间: 2010-1-8 16:59 标题: Re: 数组计算moving std问题 太赞了,原来SQL这么强大!!!我得好好学学了。