我正在尝试获取 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
我得到不同的结果。
我做错了吗?
需要你的帮助。
使用样本数据在 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)