【问题标题】:Finding the midpoint of three years寻找三年的中点
【发布时间】:2018-03-19 15:21:26
【问题描述】:

我有一个数据集,它代表三年内的销售额:

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 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;

【问题讨论】:

  • 能否请您附上您迄今为止尝试过的内容?这在数据步骤中似乎相当简单。
  • 我认为第二行 20 30 40 1.5 的表述有误。滚动总和中点为 45/50,代表指数 1.833。 (20/20 + 25/30)

标签: sas weighted-average cumulative-frequency sas-studio


【解决方案1】:

我认为您的第二个示例是错误的,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 不直接对应于我所知道的任何众所周知的统计数据。它更像是某种具有统一按比例分配的加权中位数。

【讨论】:

    猜你喜欢
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 2018-03-27
    • 2021-01-28
    • 2013-06-23
    • 2021-11-22
    • 1970-01-01
    • 2012-07-09
    相关资源
    最近更新 更多