看讨论真长知识啊。
可以先算出每人每天的no,再merge到原表。用个十万ID的fake数据试了试,没出错。
data t1;
seed =12345;
do ID =1 to 100000;
rdm1 = ceil (abs(rand('UNIFORM') *20));
do i=1 to rdm1;
date =ceil (abs(rand('UNIFORM') *5));
ticker =ceil(round(rand('UNIFORM'), .001)*15);
output;
end;
end;
format date mmddyy10.;
drop seed rdm1 i;
run;
proc sql;
create table test0 as
select a.id, a.date, count(distinct b.ticker) as no
from t1 a,t1 b
where b.id=a.id
and b.date<=a.date
and b.date>=a.date-365
group by a.id, a.date;
create table test as
select a.*,b.no
from t1 a left join test0 b
on a.id=b.id and a.date=b.date;
quit;


雷达卡




京公网安备 11010802022788号







