z**o 发帖数: 149 | 1 一列数据,想知道每个number在整体的percentile,没找到sas里直接能做的procedure
,用macro的话:
data a1; input x;
datalines;
2
6
3
2
2
1
3
8
6
10
5
9
1
6
2
5
10
;
proc univariate data=a1 noprint;
var x;
output out=a2 pctlpre=p_ pctlpts= 1 to 100 by 1;
run;
proc sql;
create table a3 as
select *
from a1, a2
;
quit;
%macro mc1;
data a4; set a3;
%do i=1 %to 99;
%if x>=p_&i. %then pctl=i; *请教大家 这个macro该怎么写?;
%end;
run;
%mend mc1;
%mc1
多谢!!! |
w********m 发帖数: 1137 | 2 proc freq;
tables x;
run; |
y****n 发帖数: 46 | 3 proc sql;
select x,count(*)/tot*100 as pct format=5.2
from (select x,count(*) as tot from a1)
group by x
;
quit; |
C******t 发帖数: 72 | 4 proc rank data=a1 groups=100 out=a2;var x;ranks x_percentile;run; |
z**o 发帖数: 149 | 5 多谢回复!这个也是frequency distribution吧
【在 y****n 的大作中提到】 : proc sql; : select x,count(*)/tot*100 as pct format=5.2 : from (select x,count(*) as tot from a1) : group by x : ; : quit;
|
z**o 发帖数: 149 | 6 多谢!
【在 C******t 的大作中提到】 : proc rank data=a1 groups=100 out=a2;var x;ranks x_percentile;run;
|
D********r 发帖数: 4 | 7 After the code:
proc univariate data=a1 noprint;
var x;
output out=a2 pctlpre=p_ pctlpts= 1 to 100 by 1;
run;
Add
proc transpose data=a2 out=a3;
run; |
P****D 发帖数: 11146 | 8 这个是输出所有的百分位数吧。记不清syntax。
【在 D********r 的大作中提到】 : After the code: : proc univariate data=a1 noprint; : var x; : output out=a2 pctlpre=p_ pctlpts= 1 to 100 by 1; : run; : Add : proc transpose data=a2 out=a3; : run;
|