问题
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