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!,
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;
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
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;
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.
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;
Thank you all very much! I learned a lot!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.