LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 1999, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 18 Oct 1999 19:56:13 -0700
Reply-To:   "Lauren E. Haworth" <haworthl@MINDSPRING.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Lauren E. Haworth" <haworthl@MINDSPRING.COM>
Organization:   MindSpring Enterprises
Subject:   Re: Row percentages in a TABULATE procedure

[This followup was posted to comp.soft-sys.sas and a copy was sent to the cited author.]

In article <MPG.1273f4a9184d4dbe98969c@news.mindspring.com>, haworthl@mindspring.com says... > [This followup was posted to comp.soft-sys.sas and a copy was sent to the > cited author.] > > In article <c3YN3.1257$IZ5.19884@news.rdc1.ct.home.com>, > rferris@rxremedy.com says... > > I would like to run a Tabulate which has subtotals in the columns and I want > > to get row percentages as a percent of the entire row total, not the > > subtotal. Here is a simple example of what I have tried: > > > > Data temp; > > input a b c; > > 1 1 1 > > 1 1 2 > > 2 1 1 > > 2 1 2 > > 1 2 1 > > 1 2 2 > > 2 2 1 > > 2 2 2 > > ; > > > > Proc tabulate; > > class a b c; > > table a,b*c*pctn<a>; > > run; > > > > The row percentages under c add up to 100% for each b group. The b > > percentages are percentages of the entire row. What I would like is to have > > both the c percentages and the b percentages as a percentage of the row > > total. Is there a simple way to do this? > > > > Thanks. > > Richard Ferris > > Rx Remedy, Inc. > > rferris@rxremedy.com > > > > > > > Richard, > > To get row percentages, use the column variables as the denominator, > as in the code below: > > Proc tabulate; > class a b c; > table a,b*c*pctn<b*c>; > run; > > -- Lauren Haworth > author "PROC TABULATE By Example"

Richard,

After reading your original post more carefully, I realized that you also wanted to know how to get row percentages when you have subtotals in the columns.

The code is as follows:

Proc tabulate; class a b c; table a,b*(c all)*pctn<b*c b*all>; run;

And the output looks like this:

------------------------------------------------------------------ | | b | | |-----------------------------------------| | | 1 | 2 | | |--------------------+--------------------| | | c | | c | | | |-------------| |-------------| | | | 1 | 2 | All | 1 | 2 | All | | |------+------+------+------+------+------| | | PctN | PctN | PctN | PctN | PctN | PctN | |----------------------+------+------+------+------+------+------| |a | | | | | | | |----------------------| | | | | | | |1 | 25| 25| 50| 25| 25| 50| |----------------------+------+------+------+------+------+------| |2 | 25| 25| 50| 25| 25| 50| ------------------------------------------------------------------

Again, I used the column definition as the denominator in order to get a row percentage. The only trick here is that you can't have parentheses in a denominator definition, so instead of b*(c all) I had to use <b*c b*all>.

-- Lauren


Back to: Top of message | Previous page | Main SAS-L page