简体   繁体   English

如何按组对SAS中的观测值进行汇总?

[英]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;

You can use proc means and you will the mean plus a bunch of other stats: more examples here for proc means . 您可以使用proc means更多的例子:你会平均再加上一堆其他属性的这里proc means

proc means data=have  noprint;
by match;
output out=want ;

Output: 输出:

输出平均值

This can be done very easily using proc summary or proc means . 使用proc summaryproc 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM