|
自己想出来了,不过多谢各位!!
DATA test;
input BRAND $ Week Price;
CARDS;
111 1 1
111 1 2
112 1 3
112 1 4
111 2 5
111 2 6
112 2 7
112 2 8
;
RUN;
PROC SQL;
create table test2 as
select *,mean(price) as total_mean, count(price) as count_price from test
group by WEEK;
QUIT;
PROC SQL;
create table test3 as
select *,mean(price) as total_mean2, count(price) as count_price2 from test
group by WEEK, BRAND;
QUIT;
DATA test4;
MERGE test test2 test3;
BY BRAND;
total2=total_mean2*count_price2;
comptotal=total-total2;
compcount=count_price-count_price2;
compavg=comptotal/compcount;
RUN;
|