PDA

View Full Version : SAS - Proc Tabulate - Percent of Total


1695814
05-07-2003, 01:02 PM
Is there a command in SAS - Proc Tabulate so that I can get the percentage of the total of a variable?

I imagine the output would look something like this:

---------------------------
|.......|....CT....|....CT....|
|.......|-------- +---------+
|.......|..SUM...|.....%.....|
|-----+--------+----------+
|class|..........|..............|
|------|...........|..............|
|AA...|___732|__20.80|
|-----+--------+----------+
|BB...|___005|__00.14|
|-----+--------+----------+
|CC...|___440|__12.50|
|-----+--------+----------+
|DD...|___777|__22.07|
|-----+--------+----------+
|EE...|____782|__22.22|
|-----+--------+----------+
|FF...|____784|__22.27|
---------------------------
|ALL..|__3,520|__100.00|
---------------------------

Here's my proc tabulate statement now:
PROC TABULATE;
CLASS class;
VAR CT;
TABLE class ALL,
CT*F=COMMA8.0
CT*(??????<CT>)*F=COMMA10.2


Where ?????? is where the secret code goes...at least I think it does.

OK, thanks.

Kiitos
05-07-2003, 05:55 PM
The following is from a SAS On-line documentation:

Calculating Percentages
The following statistics print the percentage of the value in a single table cell in relation to the total of the values in a group of cells. No denominator definitions are required; however, an analysis variable may be used as a denominator definition for percentage sum statistics. REPPCTN and REPPCTSUM statistics--print the percentage of the value in a single table cell in relation to the total of the values in the report.
COLPCTN and COLPCTSUM statistics--print the percentage of the value in a single table cell in relation to the total of the values in the column.
ROWPCTN and ROWPCTSUM statistics--print the percentage of the value in a single table cell in relation to the total of the values in the row.
PAGEPCTN and PAGEPCTSUM statistics--print the percentage of the value in a single table cell in relation to the total of the values in the page.

This example shows how to use three percentage sum statistics: COLPCTSUM, REPPCTSUM, and ROWPCTSUM.
options nodate pageno=1 linesize=105 pagesize=60;
data fundrais;
length name $ 8 classrm $ 1;
input @1 team $ @8 classrm $ @10 name $
@19 pencils @23 tablets;
sales=pencils + tablets;
cards;
BLUE A ANN 4 8
RED A MARY 5 10
GREEN A JOHN 6 4
RED A BOB 2 3
BLUE B FRED 6 8
GREEN B LOUISE 12 2
BLUE B ANNETTE . 9
RED B HENRY 8 10
GREEN A ANDREW 3 5
RED A SAMUEL 12 10
BLUE A LINDA 7 12
GREEN A SARA 4 .
BLUE B MARTIN 9 13
RED B MATTHEW 7 6
GREEN B BETH 15 10
RED B LAURA 4 3
;

proc format;
picture pctfmt low-high='009 %';
run;

title "Fundraiser Sales";

proc tabulate format=7.;
class team classrm;
var sales;
table (team all)*sales=' ',
classrm='Classroom'*(sum
colpctsum*f=pctfmt9.
rowpctsum*f=pctfmt9.
reppctsum*f=pctfmt9.)
all
/rts=20 row=float;
run;
Hope that helps!