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 |
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.