## two-way percentages in proc tabulate

Occasional Learner
Posts: 1

# two-way percentages in proc tabulate

suppose I have a dataset so that I use

proc tabulate  data = a ;

class a b ;

table a, b ;

run ;

and I get

b

a      0      1

0      2     4

1      3     1

what I want is margins on *both* sides and then percentages of the total on both margins: that is:

b

a       0       1        all

0      20     40       60

1      30     10       40

all   50     50     100

I have a grim suspicion that this is not possible, but I would like to be proven wrong.

Bendix Carstensen

Senior Statistician

Steno DIabetes Center Copenhagen

Posts: 1,837

## Re: two-way percentages in proc tabulate

Without testing, code should be like:

``````proc tabulate  data = a ;

class a ;
var b;

table (a all),
(b all) * (pctn colpctn);

run ;``````
Occasional Contributor
Posts: 8

## Re: two-way percentages in proc tabulate

Hello,

You can try this:

``````proc freq data=a;
tables a*b / nocol nocum norow nofreq;
run;``````

I hope this helps,

FloT

Super User
Posts: 13,583

## Re: two-way percentages in proc tabulate

@bendix wrote:

suppose I have a dataset so that I use

proc tabulate  data = a ;

class a b ;

table a, b ;

run ;

and I get

b

a      0      1

0      2     4

1      3     1

what I want is margins on *both* sides and then percentages of the total on both margins: that is:

b

a       0       1        all

0      20     40       60

1      30     10       40

all   50     50     100

I have a grim suspicion that this is not possible, but I would like to be proven wrong.

Bendix Carstensen

Senior Statistician

Steno DIabetes Center Copenhagen

Provide an actual data set and what the expected results would be.

If you do not provide any additional request in the Table statement of Proc Tabulate then the result for Class variables is a count.

You can request PCTN percentage of table count, RowPctN percentage of row count and ColPctN percentage of column counts.

specific statistic requests may work. I think this is what you are looking for:

```data work.a;
input a b;
datalines;
0 0
0 0
0 1
0 1
0 1
0 1
1 0
1 0
1 0
1 1
;
run;

proc tabulate data=work.a;
class a b;
table a all,
b*(pctn) all*colpctn
;
run;```
Discussion stats
• 3 replies
• 108 views
• 1 like
• 4 in conversation