Programming the statistical procedures from SAS

Frequency statistics for a big group of binary variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Frequency statistics for a big group of binary variables

Hi all!

First time here Smiley Happy

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
Grand Advisor
Posts: 10,055

Re: Frequency statistics for a big group of binary variables

Assuming 0/1 coding and not some other binary.

proc tabulate data=your dataset name;

     var var1-var50;

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

run;

View solution in original post


All Replies
Respected Advisor
Posts: 4,606

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
Respected Advisor
Posts: 3,773

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;

Grand Advisor
Posts: 16,916

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
Grand Advisor
Posts: 10,055

Re: Frequency statistics for a big group of binary variables

Assuming 0/1 coding and not some other binary.

proc tabulate data=your dataset name;

     var var1-var50;

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

run;

Occasional Contributor
Posts: 10

Re: Frequency statistics for a big group of binary variables

Thank you all very much! I learned a lot!

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 263 views
  • 6 likes
  • 5 in conversation