Quartz | Level 8

## Percentage within each category

Hello,

I have a dataset as below:

```data have;
input exam \$ passed;
datalines;
A 0
A 1
B 1
C 0
D 1
E 0
E 1
;
run;```

Using tabulate procedure i am able to generate total counts correctly, but in ColPctn, i would like to have percentages within in each exam. for instance: first row of output should

be 50% (1 passed / 2 all) = 0.5 , and not

This is the code i am using below  :
title "CrossTab";

```proc tabulate data = have;
class exam;
var passed;
table exam ,
passed*( N SUM='Passed'*f= 10. colpctn);
keylabel all = "Total";
run;```

and the output which is not coming as i need:

passed
N Passed ColPctN
exam 2 1 28.57
A
B 1 1 14.29
C 1 0 14.29
D 1 1 14.29
E 2 1 28.57

I would appreciate any suggestion .

1 ACCEPTED SOLUTION

Accepted Solutions
PROC Star

## Re: Percentage within each category

Percentages can be tricky but in this case there is an easy solution:

``````proc tabulate data = have;
class exam;
var passed;
table exam ,
passed*( N SUM='Passed'*f= 10. mean='% Passed'*f=percent8.2);
keylabel all = "Total";
run;``````

When dealing with a 0/1 variable, the mean is the same as the percentage of "1" values.

2 REPLIES 2
PROC Star

## Re: Percentage within each category

Percentages can be tricky but in this case there is an easy solution:

``````proc tabulate data = have;
class exam;
var passed;
table exam ,
passed*( N SUM='Passed'*f= 10. mean='% Passed'*f=percent8.2);
keylabel all = "Total";
run;``````

When dealing with a 0/1 variable, the mean is the same as the percentage of "1" values.

Quartz | Level 8