## Frequency statistics for a big group of binary variables

Solved
Occasional Contributor
Posts: 10

# Frequency statistics for a big group of binary variables

Hi all!

First time here

I'm looking for a neat way to arrange frequency statistics (percentage of positive response) for a large set (~55) of binary variables in a data set.

I am familiar with PROC FREQ, but it makes 55 distinct tables, and this is inelegant when presenting the work to others.

Is there a more elegant way to do what I need? (i.e. arrange those 55 percentages?)

Thanks very much!,

Accepted Solutions
Solution
‎05-25-2012 11:14 AM
Super User
Posts: 11,838

## Re: Frequency statistics for a big group of binary variables

Assuming 0/1 coding and not some other binary.

var var1-var50;

table var1-var50,n='Count' sum='Number of ones' mean= 'Percent ones'*f=percent10.2;

run;

All Replies
Posts: 5,057

## Re: Frequency statistics for a big group of binary variables

Assuming you have an ID variable identifying each observation, as in the following example :

/* Example dataset */

data test;
array x{15};
do id = 1 to 10;
do i = 1 to dim(x);
x{i} = rannor(-1);
end;
output;
end;
run;

proc transpose data=test out=list;
var x:;  /* x: is the list of variable names */
by id;
run;

/* calculate the percentages with SQL */

proc sql;
select _name_ as variable label="Variable", sum(col1>0)/count(*) as pctPos format=percent7.1 label="Percent positive"
from list
group by _name_;
quit;

PG

PG
Posts: 3,805

## Re: Frequency statistics for a big group of binary variables

The MEAN of 0/1=Proportion, N=N, and SUM=COUNT.

PROC CORR?

data test;

array x[15];

do id = 1 to 10;

trt = rantbl(123,.55);

do i = 1 to dim(x);

x = rantbl(123,.3)-1;

end;

output;

end;

run;

proc sort data=test;

by trt;

run;

ods output

SimpleStats=stats

(

keep=trt var: nobs mean sum

rename=(mean=pct sum=count)

)

;

proc corr nocorr;

by trt;

var x:;

run;

proc print;

format pct percent8.1;

run;

Super User
Posts: 20,785

## Re: Frequency statistics for a big group of binary variables

If you have 55 variables with 1/0 then I'd use proc means to get the stats suggested by data _null_ and create a table that you could sort descending and/or use to create a bar chart as well.

Solution
‎05-25-2012 11:14 AM
Super User
Posts: 11,838

## Re: Frequency statistics for a big group of binary variables

Assuming 0/1 coding and not some other binary.

var var1-var50;

table var1-var50,n='Count' sum='Number of ones' mean= 'Percent ones'*f=percent10.2;

run;

Occasional Contributor
Posts: 10