SAS--calculating mean by multiple groups

和自甴很熟 提交于 2019-12-12 04:46:51

问题


Supposing a dataset as following:

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

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;

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


回答1:


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;

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=_: ?



来源:https://stackoverflow.com/questions/47444022/sas-calculating-mean-by-multiple-groups

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!