我有一个数据集,它代表了三年的销售量:
data test;
input one two three average;
datalines;
10 20 30 .
20 30 40 .
10 30 50 .
10 10 10 .
;
run;我正在寻找一种方法来找到三年的中间点,平均销售点
更新后的数据集将显示为
data test;
input one two three average;
datalines;
10 20 30 2
20 30 40 1.5
10 30 50 2.1
10 10 10 1.5
;
run;因此,本质上是寻找三年中销售的中点发生的部分。
很感谢你。
编辑:我一直在尝试的权重和proc方法
我一直在尝试使用proc均值和权重函数,但它没有给出这三年的平均值
proc means data=test noprint;
var one two three;
var one+two+three=total;
var (one+two+three)/3=Average;
var Average/weight=Average_Year;
output out=testa2
sum(Total) =
mean(Total) = ;
run;发布于 2018-03-20 19:41:36
我认为您的第二个示例是错误的,average的正确值实际上是1.833而不是1.5.如果我没有记错,下面的数据步骤代码完成了您需要的工作:
data want;
set test;
array years[3] one two three;
total = one + two + three;
midpoint = total / 2;
do i = 1 by 1 until(cum_total >= midpoint);
cum_total = sum(cum_total,years[i]);
end;
average = i - 1 + (midpoint - (cum_total - years[i]))/years[i];
run;我认为很难通过proc means重现这个逻辑,因为您的average并不直接对应于我所知道的任何众所周知的统计数据。它更像是某种具有统一比例评级的加权中位数。
https://stackoverflow.com/questions/49366486
复制相似问题