[英]how to sum observations in SAS by groups?
I have an example of a dataset in the following manner 我有以下方式的数据集示例
data have;
input match percent;
cards;
0 34
0 54
0 33
0 23
1 60
1 70
1 70
1 70
;
Essentially I want to sum the observations that are associated with 0
and then divide them by the number of 0
s to find the average. 本质上,我想对与
0
相关的观察值求和,然后将它们除以0
的数量以找到平均值。 eg 34+54+33+23/4 then do the same for 1
's 例如34 + 54 + 33 + 23/4,然后对
1
进行同样的操作
I looked at PROC TABULATE. 我看着PROC TABULATE。 However, I don't understand how to carry out this procedure.
但是,我不知道如何执行此过程。
Many ways to do this in SAS. SAS中有许多方法可以做到这一点。 I would use
PROC SQL
我会使用
PROC SQL
proc sql noprint;
create table want as
select match,
mean(percent) as percent
from have
group by match;
quit;
This can be done very easily using proc summary
or proc means
. 使用
proc summary
或proc means
可以很容易地做到这一点。
proc summary data=have nway missing;
class match;
var percent;
output out=want mean=;
run;
You can also output a variety of other statistics using these procedures. 您还可以使用这些过程输出各种其他统计信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.