全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1960 8
2013-10-02
悬赏 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;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
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;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-10-4 12:24:25
复制代码
最后去除number一列就行了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-10-8 09:04:24
龙潭丰乐 发表于 2013-10-4 12:24
最后去除number一列就行了
很正统的处理方法,当大分类的count相同时,有可能会发生混乱,总之非常感谢!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

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:

复制代码

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

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

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.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群