🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 02-04-2014 03:14 PM
(1329 views)
Hello ,
I'm trying to get the percentage of 1=Yes values for each question (Q1,Q2 etc) within each ID variable. Below is my data sample and desired output.
I did this using PROC SQL with sub queries but I'd like to get the same results using one of SAS procedure, I don't know maybe proc tabulate or proc freq etc... Could you please help ?
Data
ID | Q1 | Q2 | Q3 | Q4 |
A | 1 | 1 | 1 | 1 |
A | 1 | 0 | 1 | 0 |
A | 0 | 0 | 1 | 0 |
A | 1 | 1 | 0 | 0 |
B | 1 | 1 | 0 | 0 |
B | 0 | 1 | 0 | 1 |
B | 0 | 0 | 1 | 0 |
Output
ID | Q1_P | Q2_P | Q3_P | Q4_P |
A | 0.75 | 0.5 | 0.75 | 0.25 |
B | 0.3333 | 0.666667 | 0.3333 | 0.3333 |
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I don't know if it needs transpose or not. Maybe you just want percent.
proc summary data=q nway;
class ID;
output out=percent mean(q:)=;
run;
class ID;
output out=percent mean(q:)=;
run;
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would go ahead as get N, count, and percent.
data q;
input ID:$1. Q1-Q4;
cards;
A 1 1 1 1
A 1 0 1 0
A 0 0 1 0
A 1 1 0 0
B 1 1 0 0
B 0 1 0 1
B 0 0 1 0
;;;;
run;
ods select none;
proc means n sum mean stackods;
class id;
ods output summary=summary(rename=(sum=count mean=percent));
run;
ods select all;
proc print;
format _all_;
run;
input ID:$1. Q1-Q4;
cards;
A 1 1 1 1
A 1 0 1 0
A 0 0 1 0
A 1 1 0 0
B 1 1 0 0
B 0 1 0 1
B 0 0 1 0
;;;;
run;
ods select none;
proc means n sum mean stackods;
class id;
ods output summary=summary(rename=(sum=count mean=percent));
run;
ods select all;
proc print;
format _all_;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, it seems like your process also needs transpose procedure for the output. I'll work on that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I don't know if it needs transpose or not. Maybe you just want percent.
proc summary data=q nway;
class ID;
output out=percent mean(q:)=;
run;
class ID;
output out=percent mean(q:)=;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much, I learned another procedure today...way better than Proc sql....
Best Regards...