517 4

# [SAS EM] SAS分组求和问题 [推广有奖]

• 0关注
• 1粉丝

57%

-

0

12 个

0 点

1 点

0 点

247 点

15

0

53 小时

2014-10-18

2019-1-15

Lindsay林 发表于 2018-8-9 23:21:54 |显示全部楼层

 SB year month mv fenzi BH 2000 11 a x BH 2000 11 b y rp=(x+y+z)/(a+b+c) BH 2000 11 c z BH 2000 12 BH 2000 12 BH 2000 12 BH 2001 1 BH 2001 1 BH 2001 1 BL 2000 11 BL 2000 11 BL 2000 11 BL 2000 12 BL 2000 12 BL 2000 12 BL 2001 1 BL 2001 1 BL 2001 1

 SB year month rp BH 2000 11 BH 2000 12 BH 2001 1 BL 2000 11 BL 2000 12 BL 2001 1

Lindsay林 发表于 2018-8-10 22:01:25 |显示全部楼层
 proc sql; create table shuju as select SB,year,month,sum(mv) as mv,sum(fenzi) as fenzi,sum(fenzi)/sum(mv) as rp from aa group by 1,2,3; quit;

whymath 发表于 2018-8-11 21:54:51 |显示全部楼层

steven_1017 发表于 2018-8-17 11:46:08 |显示全部楼层
 里面的mv，fenzi，我随便编了一些数字，但大概按照你希望的business写了一下，你看看。 data work.test; input sb \$ year month mv fenzi; datalines; BH 2000 11 4 3 BH 2000 11 5 3 BH 2000 11 2 6 BH 2000 12 8 1 BH 2000 12 2 5 BH 2000 12 4 3 BH 2001 1 3 6 BH 2001 1 7 6 BH 2001 1 5 5 BL 2000 11 3 3 BL 2000 11 8 3 BL 2000 11 2 4 BL 2000 12 5 3 BL 2000 12 2 2 BL 2000 12 6 9 BL 2001 1 4 7 BL 2001 1 8 1 BL 2001 1 3 6 ; run; proc sort data = work.test ; by sb year month; run; data work.test1 (drop= mv fenzi mvsum fenzisum); set work.test; by sb year month; if first.month then do; mvsum = 0; fenzisum = 0; end; mvsum + mv; fenzisum + fenzi; if last.month then do; rp = fenzisum/mvsum; output; end; run;