BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hypermonkey2
Calcite | Level 5

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!,

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

5 REPLIES 5
PGStats
Opal | Level 21

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
data_null__
Jade | Level 19

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;

Reeza
Super User

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.

ballardw
Super User

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;

hypermonkey2
Calcite | Level 5

Thank you all very much! I learned a lot!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

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