本文介绍了SAS:PROC TABULATE 重新排列标题子组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

问题:如何控制 PROC TABULATE 输出中子组的顺序?

Question: How do I control the order of subgroups in the output of PROC TABULATE?

例如,假设我有这个输出,即 segment 中的 (A, B):

For instance, suppose I have this output, namely (A, B) within segment:

data example;
    input group $ segment $;
    datalines;
    1 A
    1 B
    2 A
    2 A
    3 B
    3 B
    ;
run;

proc tabulate data = example;
    class group segment;
    table group all, all = 'Total'*n segment*n;
run;

+-----------------------+------------+-------------------------+
+                       +            +         segment         +
+                       +            +------------+------------+
+                       +   Total    +     A      +     B      +
+                       +------------+------------+------------+
+                       +     N      +     N      +     N      +
+-----------------------+------------+------------+------------+
+    group              +            +            +            +
+-----------------------+            +            +            +
+    1                  +     2.00   +     1.00   +     1.00   +
+-----------------------+------------+------------+------------+
+    2                  +     2.00   +     2.00   +        .   +
+-----------------------+------------+------------+------------+
+    3                  +     2.00   +        .   +     2.00   +
+-----------------------+------------+------------+------------+
+    All                +     6.00   +     3.00   +     3.00   +
+-----------------------+------------+------------+------------+

我如何重新排列 segment 的子组以相反的顺序出现,(B, A)?

How would I reorder the subgroups of segment to appear in the opposite order, (B, A)?

+-----------------------+------------+-------------------------+
+                       +            +         segment         +
+                       +            +------------+------------+
+                       +   Total    +     B      +     A      +
+                       +------------+------------+------------+
+                       +     N      +     N      +     N      +
+-----------------------+------------+------------+------------+
+    group              +            +            +            +
+-----------------------+            +            +            +
+    1                  +     2.00   +     1.00   +     1.00   +
+-----------------------+------------+------------+------------+
+    2                  +     2.00   +        .   +     2.00   +
+-----------------------+------------+------------+------------+
+    3                  +     2.00   +     2.00   +        .   +
+-----------------------+------------+------------+------------+
+    All                +     6.00   +     3.00   +     3.00   +
+-----------------------+------------+------------+------------+

似乎可以选择使用 DESC 或 DESCENDING= 对子组进行排序,但这两种方法都不适合我.我的部分问题可能是我使用的术语.我不认为A"和B"在 SAS 词典中被称为子组.

It seems like there may be an option to order subgroups using DESC or DESCENDING=, but neither of those work for me. Part of my problem may be the terminology I'm using. I don't think "A" and "B" are called subgroups within the SAS lexicon.

推荐答案

如果你先对数据进行排序,然后再使用 order=data 你应该能够得到你需要的:

If you sort the data first and then user order=data you should be able to get what you need:

proc sort data=example;
 by group descending segment;
run;

proc tabulate data = example order=data;
    class group segment;
    table group all, all = 'Total'*n segment*n;
run;

这篇关于SAS:PROC TABULATE 重新排列标题子组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 13:14