New to SAS here, I appreciate any help!
I have a spreadsheet that looks this:
Name | Question 1 | Question 2 | Question 3 |
John Doe | Yes | Yes | No |
Jane Smith | No | Yes | Yes |
How do I count the frequency for each column so the output looks like this:
Question 1 | Question 2 | Question 3 | |
Yes | 1 | 2 | 1 |
No | 1 | 0 | 1 |
1. Transpose main data set to a long format
2. Run a PROC FREQ
proc transpose data=have out=long;
by name;
var question1-question3;
run;
proc freq data=long;
table col1*_name_; *you may need to confirm name of col1 in wide data set;
run;
This should work regardless of the number of questions or responses.
@kc1895 wrote:
New to SAS here, I appreciate any help!
I have a spreadsheet that looks this:
Name Question 1 Question 2 Question 3 John Doe Yes Yes No Jane Smith No Yes Yes
How do I count the frequency for each column so the output looks like this:
Question 1 Question 2 Question 3 Yes 1 2 1 No 1 0 1
data have;
input Name & $10. (Question1-Question3) ($);
cards;
John Doe Yes Yes No
Jane Smith No Yes Yes
;
proc transpose data=have out=temp(drop=name) ;
by name notsorted;
var Question1-Question3;
run;
proc report data=temp completerows;
column col1 _name_;
define _name_/across;
define col1/group;
run;
NAME OF FORMER VARIABLE | |||
---|---|---|---|
COL1 | Question1 | Question2 | Question3 |
No | 1 | 0 | 1 |
Yes | 1 | 2 | 1 |
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.