Solved
Contributor
Posts: 29

# How to Create a Frequency Table for a Check All That Apply Question

data  have;

input ID Reason1 Reason2     Reason3     Reason4      Reason5

cards;

1     0     1     1     0     1

2     1     0     0     0     0

3     1     1     0     0     1

4     0     1     0     1     0

5     1     0     0     0     0

6     1     0     0     0     0

;

run;

I would like a frequency table showing

Reason          Count          Percentage

Reason1            4                 36.36%

Reason2            3                 27.27%

Reason3            1                 9.09%

Reason4            1                 9.09%

Reason5            2                 18.18%

Total                  11                100%

I've tried playing around with transpose and arrays to no avail. Thank you!

Accepted Solutions
Solution
‎07-06-2015 10:32 PM
Posts: 1,270

## Re: How to Create a Frequency Table for a Check All That Apply Question

proc transpose data=have out=want(rename=(_name_=Reason));

by id;

run;

proc sql;

select Reason,sum(col1=1) as count,sum(col1=1)/(select sum(col1) from want) as percentage format percent6.1

from want

group by Reason;

quit;

All Replies
Super User
Posts: 23,683

## Re: How to Create a Frequency Table for a Check All That Apply Question

Try PROC MEANS. A sum will get you the count and a mean will get you percentages.

Posts: 5,521

## Re: How to Create a Frequency Table for a Check All That Apply Question

MEANS and ARRAY can do it:

proc means data=have noprint;

var Reason1-Reason5;

output out=temp sum=;

run;

data want;

set temp;

array r{*} reason:;

do i = 1 to dim(r);

Reason = vname(r{i});

Count = r{i};

Percentage = r{i} / _freq_;

output;

end;

reason = "Total";

count = _freq_;

percentage = 1;

output;

format percentage percent8.2;

keep reason count percentage;

run;

proc print data=want noobs; run;

PG

PG
Solution
‎07-06-2015 10:32 PM
Posts: 1,270

## Re: How to Create a Frequency Table for a Check All That Apply Question

proc transpose data=have out=want(rename=(_name_=Reason));

by id;

run;

proc sql;

select Reason,sum(col1=1) as count,sum(col1=1)/(select sum(col1) from want) as percentage format percent6.1

from want

group by Reason;

quit;

Contributor
Posts: 29

## Re: How to Create a Frequency Table for a Check All That Apply Question

Thanks to both of you!

Super User
Posts: 23,683

## Re: How to Create a Frequency Table for a Check All That Apply Question

How would you interpret that 36.36 percent? I would assume that you would want 4/6 = 67%

Contributor
Posts: 29

## Re: How to Create a Frequency Table for a Check All That Apply Question

I had wanted 4/11 = 36.36%. While there were 6 respondents, there were 11 total responses (check all that apply).

Super User
Posts: 23,683

## Re: How to Create a Frequency Table for a Check All That Apply Question

I'm not saying it's wrong, I'm really trying to understand the concept of how that would be interpreted and where it would be applicable.  I work with survey data a lot so knowing when a measure like that would be useful would be good. Are you able to share some more context on how that would be interpreted?

Contributor
Posts: 29