SAS--计算多组均值 [英] SAS--calculating mean by multiple groups

查看:63
本文介绍了SAS--计算多组均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设一个数据集如下:

id    date         var1
001   20170101    1
001   20170101    2 
001   20170101    3
001   20170102    1
001   20170102    2
002   20170101    1
002   20170101    2
002   20170102    1
002   20170102    2

我通过以下代码计算每个日期每个id的平均值.

I to calculate the mean for each id in each date through following code.

proc summary data=HAVE nway;
class id date;
var var1 ;
output out=WANT(drop=_:) mean=mean std=std;
run;

但是,WANT 只表示日期、均值和标准差,不包含 ID.我怎么能解决这个问题?

However, the WANT only represents date, mean, and std, but does not contain ID. How could I solve this problem?

推荐答案

我无法重现您的问题.通过后

I wasn't able to reproduce your issue. After passing

   data have;
     informat date yymmdd8.;
     input id date  var1;

   datalines;
   001 20170101 1
   001   20170101    2 
   001   20170101    3
   001   20170102    1
   001   20170102    2
   002   20170101    1
   002   20170101    2
   002   20170102    1
   002   20170102    2
   ;
   run;

   proc summary data=HAVE nway;
     class id date;
     var var1 ;
     output out=WANT(drop=_:) mean=mean std=std;
   run;

我得到了像你展示的那样的 HAVE 数据集,但结果数据集 WANT 包括两个类变量.也许您的实际 id 变量以下划线为前缀,并以 drop=_: 结束?

I got the HAVE dataset like like you showed but the resulting dataset WANT includes both class variables. Maybe your actual id variable is prefixed with underscore and dies with the drop=_: ?

这篇关于SAS--计算多组均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆