|
沙发

楼主 |
发表于 2011-6-24 23:59:49
|
只看该作者
Re: 大数据库分组计算问题
没有完全看懂你的data,比如date time price,我就随意修改了一下,比如:date time我就看作一个变量,且添加了price值,。
[code:mvu5ag2n]
DATA A;
input ID $ time yymmdd8. price;
format time date9.;
cards;
AA 20090112 20
AA 20090116 23
AA 20090211 36
AA 20090219 30
BB 20050327 12
BB 20050323 15
CC 20050420 17
DD 20030420 100
;
run;
proc sql;
create table aa(drop=cnt) as
select *,mean(price) as avg_p format=8.2
from (select *,count(*) as cnt
from (select *,count(distinct ID) as total_ID,year(time) as yr,month(time) as month
from a)
group by id,month
having cnt>1)
group by id,yr,month
having time=min(time)
order by id;
quit;[/code:mvu5ag2n] |
|