简体   繁体   中英

Weighted mean in SAS

I have problem with some SAS code. Within first weighted mean grouping by "date", I want to compute again weighted mean using "group" with by option and "w2" as weight. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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