朋友问到如何如何输出频数最小观测值的解决办法,想到SAS的sql,还是挺快捷的。跟大家分享一下,也欢迎大家分享更加快捷的方式。
- data a;
- input x y;
- cards;
- 1 1
- 1 2
- 1 3
- 1 4
- 2 2
- 2 3
- 2 4
- 3 3
- 3 4
- 4 4
- ;
- run;
- proc sql;
- create table data_count as
- select x, count(*) as x_n
- from a
- group by x
- ;
- proc print data=data_count;
- run;
- proc sql;
- create table data_count_minimum as
- select x
- from data_count
- having x_n = min(x_n)
- ;
- proc print data=data_count_minimum;
- run;
- proc sql;
- create table data_count_minimum as
- select x
- from
- (
- select x, count(*) as x_n
- from a
- group by x
- )
- having x_n = min(x_n)
- ;
- proc print data=data_count_minimum;
- run;