Reputation: 4554
Question: How do I control the order of subgroups in the output of PROC TABULATE?
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 +
+-----------------------+------------+------------+------------+
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 +
+-----------------------+------------+------------+------------+
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.
Upvotes: 0
Views: 122
Reputation: 974
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;
Upvotes: 2