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

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

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
Trusted Advisor
Posts: 1,203

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;

View solution in original post


All Replies
Grand Advisor
Posts: 17,464

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.

Respected Advisor
Posts: 4,609

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
Trusted Advisor
Posts: 1,203

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!

Grand Advisor
Posts: 17,464

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).

Grand Advisor
Posts: 17,464

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

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

Gotchya. The percentages aren't to be used to be in the context of statistical analyses. More so anecdotally as the investigators were looking to get an understanding of the top responses within a wide range of choices that could be checked off (e.g., knowing the top reasons for getting tested).

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 323 views
  • 5 likes
  • 4 in conversation