楼主: Tigflanker
1743 8

[问答] 求助频数排序问题 [推广有奖]

  • 8关注
  • 18粉丝

副教授

49%

还不是VIP/贵宾

-

威望
0
论坛币
2321 个
通用积分
9.8528
学术水平
179 点
热心指数
194 点
信用等级
167 点
经验
27443 点
帖子
622
精华
0
在线时间
851 小时
注册时间
2011-3-27
最后登录
2023-5-14

100论坛币
求助各位一个问题:

例如我有如下数据集:

data a;
input class1 $ class2 $ count @@;
cards;
A A 3
A a 1
A b 2
B B 7
B c 1
B d 2
B e 4
;
run;

class1是大分类,class2是class1的子分类,count是他们的计数。

我想这样分类:首先按照大分类的合计来排,那么B的四条观测排最上面,A的排最下面(当然分类不止两个);然后B的小分类再继续排。。。

如果直接用proc sort,那么B的最后一条观测都会超过A。。。

换句话说:我就是想按照class1的合计观测来决定位置,然后再整个区块移动,不知有无办法?谢谢。

最佳答案

邓贵大 查看完整内容

data a; input class1 $ class2 $ count @@; cards; A A 3 A a 1 A b 2 B B 7 B c 1 B d 2 B e 4 ; proc means data=a order=freq nway noprint; class class1 class2; freq count; output out=hell(drop=_type_ rename=(_freq_=count)); run; proc print data=hell;
关键词:Count cards Input Data card count

回帖推荐

邓贵大 发表于2楼  查看完整内容

data a; input class1 $ class2 $ count @@; cards; A A 3 A a 1 A b 2 B B 7 B c 1 B d 2 B e 4 ; proc means data=a order=freq nway noprint; class class1 class2; freq count; output out=hell(drop=_type_ rename=(_freq_=count)); run; proc print data=hell;
Bye SAS.
若有缘,能重聚。
沙发
邓贵大 发表于 2013-10-2 22:38:29 |只看作者 |坛友微信交流群
data a;
input class1 $ class2 $ count @@;
cards;
A A 3
A a 1
A b 2
B B 7
B c 1
B d 2
B e 4
;

proc means data=a order=freq nway noprint;
        class class1 class2;
        freq count;
        output out=hell(drop=_type_ rename=(_freq_=count));
run;
proc print data=hell;
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
龙潭丰乐 + 1 + 1 + 1 观点有启发
Tigflanker + 1 + 1 + 1 Really Fantasy Way for me!! 3Q!!

总评分: 学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.

使用道具

藤椅
龙潭丰乐 学生认证  发表于 2013-10-4 12:24:25 |只看作者 |坛友微信交流群
  1. proc sql;
  2. create table b as
  3.    select class1,sum(count)as number
  4.     from a
  5.          group by  class1;
  6. quit;
  7. data quan;
  8. merge a b;
  9. by class1;
  10. run;
  11. proc sort data=quan ;
  12. by descending number;
  13. run;
复制代码
最后去除number一列就行了
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Tigflanker + 1 + 1 + 1 观点有启发,谢谢!

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

使用道具

板凳
Tigflanker 发表于 2013-10-8 09:04:24 |只看作者 |坛友微信交流群
龙潭丰乐 发表于 2013-10-4 12:24
最后去除number一列就行了
很正统的处理方法,当大分类的count相同时,有可能会发生混乱,总之非常感谢!!
Bye SAS.
若有缘,能重聚。

使用道具

报纸
Tigflanker 发表于 2013-10-11 18:59:26 |只看作者 |坛友微信交流群
邓贵大 发表于 2013-10-2 22:38
data a;
input class1 $ class2 $ count @@;
cards;
Hi Deng,

I have meet some problem when use this part of code.

The dataset you can find in attachment are not correctly sorted by proc means.

Maybe I use wrong option or keep wrong observation.

The result show that :

The second observation by Class 1 (the first col) value 117 didn't list in the first place.

So ,please tell me.. Thank you :)

The code I use as this:

  1. proc means data=out.a order=freq nway noprint;
  2.         class AEBODSYS AEDECOD;
  3.         freq count8;
  4.         output out=b;
  5. run;
复制代码

10/11 19:12

Maybe I find the problem.

When use proc means, the class class1 both include only class1's sum count and include class1's all sub-count.

So, N(class1) 96 + N(class2 sum) 91 > I(class1) 117 + I(class2 sum) 64




a.zip

3.44 KB

本附件包括:

  • a.sas7bdat

Bye SAS.
若有缘,能重聚。

使用道具

地板
邓贵大 发表于 2013-10-11 20:32:38 |只看作者 |坛友微信交流群
Tigflanker 发表于 2013-10-11 18:59
Hi Deng,

I have meet some problem when use this part of code.
Well, you data flawed, because the # of preferred terms do not add up to the total # given in the body class. In this case, you have to include two frequency variables in the data and PROC SORT it.
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Tigflanker + 1 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

Be still, my soul: the hour is hastening on
When we shall be forever with the Lord.
When disappointment, grief and fear are gone,
Sorrow forgot, love's purest joys restored.

使用道具

7
Tigflanker 发表于 2013-10-11 22:23:03 |只看作者 |坛友微信交流群
邓贵大 发表于 2013-10-11 20:32
Well, you data flawed, because the # of preferred terms do not add up to the total # given in the  ...
Thank you Deng, I will try this way.
Bye SAS.
若有缘,能重聚。

使用道具

8
calsunny 发表于 2015-9-9 02:38:47 |只看作者 |坛友微信交流群
  1. 为什么不可以这样?结果和二楼一样
  2. proc sort data=a;by descending class1 descending count;run;
复制代码

使用道具

9
teqel 发表于 2015-9-9 11:03:32 |只看作者 |坛友微信交流群
竟然不能回帖

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-4 20:23