I have a dataset which has about 30 dummy variables. I need to show the frequency of all the dummy variables having 1. If I want to achieve this by PROC MEANS, how can I do so? Is there any better way? The idea is to have the following logic:
if dv1=1, dv2=1, dv3=1... dv30=1 then
proc means data= zzz nway noprint;
class dv1 dv2 dv3... dv30;
output out= aaa;
run;
The imaginary dataset is like the following:
data have;
input dv1 dv2 dv3;
datalines;
1 0 1
0 0 1
1 0 0
0 1 1
0 0 1
1 1 0
0 0 0
1 0 0
0 1 0
0 0 1
0 0 0
run;Much thanks.
Regards.
Are you asking for this?
/*show the frequency of all the dummy variables having 1.*/
data have;
input dv1 dv2 dv3;
datalines;
1 0 1
0 0 1
1 0 0
0 1 1
0 0 1
1 1 0
0 0 0
1 0 0
0 1 0
0 0 1
0 0 0
run;
proc means data= have nway noprint;
var dv1-dv3;
output out= aaa(drop=_:) sum=/autoname;
run;
Are you asking for this?
/*show the frequency of all the dummy variables having 1.*/
data have;
input dv1 dv2 dv3;
datalines;
1 0 1
0 0 1
1 0 0
0 1 1
0 0 1
1 1 0
0 0 0
1 0 0
0 1 0
0 0 1
0 0 0
run;
proc means data= have nway noprint;
var dv1-dv3;
output out= aaa(drop=_:) sum=/autoname;
run;
If your variables are numeric and coded 0/1 then requesting the SUM will give you a count of the number of records with a value of 1.
If you request a Mean then that is a percentage of 1's.
proc means data= zzz nway noprint; class dv1 dv2 dv3... dv30; output out= aaa sum= ; run;
will have the variables with a sum.
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.