【问题标题】:Different results for percentiles in SAS and ExcelSAS 和 Excel 中百分位数的不同结果
【发布时间】:2019-06-02 23:35:42
【问题描述】:

我正在尝试在 SAS 中获取百分位数。我在 Excel 中得到了百分位数,我也期望在 SAS 中得到相同的结果,但是当我在 SAS 中得到百分位数时,它与在 excel 中不同。

我正在使用以下示例数据, 1 2 3 4 5 6 7 8 9 10

我用过的Excel公式是=PERCENTILE(A1:A10, K)

(K的值为0.05、0.1、0.2、0.3、0.4、0.5、0.6、0.7、0.8、0.9)

在excel中我得到的结果是

1.45、1.9、2.8、3.7、4.6、5.5、6.4、7.3、8.2、9.1

在 SAS 中我使用以下代码

data nums;
input no 9.;
datalines; 
1
2
3
4
5
6
7
8
9
10
;
run;

proc univariate data = nums noprint;
var no;
output out = pctls
        pctlpts = 5 10 20 30 40 50 60 70 80 90 
        pctlpre = no
        pctlname = pct5 pct10 pct20 pct30 pct40 pct50 pct60 pct70 pct80 pct90;
run;

在 SAS 中,我得到的结果为

1、1.5、2.5、3.5、4.5、5.5、6.5、7.5、8.5、9.5

我得到不同的结果。

我做错了吗?

需要你的帮助。

【问题讨论】:

标签: excel sas


【解决方案1】:

使用您的样本数据在 SAS 中编写您自己的百分位数函数 这是一步一步的伪代码

Sample=[1,2,3,4,5,6,7,8,9,10]
Sample size n=10
Percentile p= 0.9
(n-1)=9 (size of the array minus 1)
(n-1)p=(9*0.9)= 8.1
Integer part of (n-1)p, I = 8
Float part of (n-1)p, F=0.1
Supposing the first element of the array index is 1 and not 0
If F=0 then
  Result = Sample[I+1]
Else 
 Result= Sample[I+1]+F(Sample[I+2]-Sample[I+1]
end
Since (n-1)p has a decimal component we take the else route of the If statement, using values:
  Result= 9+0.1(10-9)
Result=9.1

【讨论】:

    猜你喜欢
    • 2011-08-22
    • 1970-01-01
    • 2020-07-16
    • 2020-04-17
    • 1970-01-01
    • 2022-07-29
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    相关资源
    最近更新 更多