简体   繁体   English

SAS中的加权平均值

[英]Weighted mean in SAS

I have problem with some SAS code. 我对某些SAS代码有疑问。 Within first weighted mean grouping by "date", I want to compute again weighted mean using "group" with by option and "w2" as weight. 在按“日期”进行的第一个加权均值分组中,我想再次使用“组”(按选项)和“ w2”作为权重来计算加权均值。 How can I do this? 我怎样才能做到这一点?

proc univariate data=set_out;
by date;
weight w1;
VAR price;
run;

The weight statement accepts only one variable, so you will need to use UNIVARIATE twice: weight语句仅接受一个变量,因此您将需要两次使用UNIVARIATE

proc sort data=have;
  by date;
proc univariate data=have;
  by date;
  weight w1;
  VAR price;
  output out=want mean=mean_price;
run;

and

proc sort data=have;
  by group;
proc univariate data=have;
  by group;
  weight w2;
  VAR price;
  output out=want mean=mean_price;
run;

If you don't want to sort the data use a CLASS statement instead of BY 如果您不想对数据进行排序,请使用CLASS语句代替BY

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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