问题:如何控制PROC TABULATE输出中子组的顺序?
例如,假设我有这个输出,即segment
中的(A,B):
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)?
+-----------------------+------------+-------------------------+
+ + + 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词典中被称为子组。
答案 0 :(得分:2)
如果您先对数据进行排序,然后再对用户order=data
进行排序,那么您应该能够获得所需的数据:
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;