o******l 发帖数: 3125 | 1 怎样把一个data set 里面所有的obs按照某个变量分成几个组。
比如说:top 30% in group A
middle 40% in group B
bottom 30% in group C
我用
proc rank data = a group =3;
var x;
ranks y;
run;
这样得到的每个group的个数都是33%左右。 |
o*******w 发帖数: 2310 | |
d******9 发帖数: 404 | 3 Use Proc Sort and data step.
proc sort data= sashelp.air out=B;
by air;
run;
data C;
set B NOBS=N;
by air;
if _N_ LE N*0.3 then group=1;
else if _N_ LE N*0.7 then group=2;
else group=3;
run;
proc freq data=C nlevels;
tables group/missing;
run; |
o*******w 发帖数: 2310 | 4 按照某个变量 not by _N_
【在 d******9 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Use Proc Sort and data step. : proc sort data= sashelp.air out=B; : by air; : run; : data C; : set B NOBS=N; : by air; : if _N_ LE N*0.3 then group=1; : else if _N_ LE N*0.7 then group=2; : else group=3;
|
o******l 发帖数: 3125 | |
d******9 发帖数: 404 | 6 Please note
data C;
set B NOBS=N;
by AIR ;
if _N_ LE N*0.3 then group=1;
else if _N_ LE N*0.7 then group=2;
else group=3;
run;
The data is presorted and then set by AIR, therefore it is ordered by the
variable Air, not by _N_, actually.
I run it in SAS already, everything is fine.
【在 o*******w 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 按照某个变量 not by _N_
|
o*******w 发帖数: 2310 | 7 GOOD!
【在 d******9 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Please note : data C; : set B NOBS=N; : by AIR ; : if _N_ LE N*0.3 then group=1; : else if _N_ LE N*0.7 then group=2; : else group=3; : run; : The data is presorted and then set by AIR, therefore it is ordered by the : variable Air, not by _N_, actually.
|