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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

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;
d6k5d3
Pyrite | Level 9
Thank you so much. Exactly this is what I have been looking for.
ballardw
Super User

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.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 836 views
  • 2 likes
  • 3 in conversation