BookmarkSubscribeRSS Feed
kc1895
Calcite | Level 5

New to SAS here, I appreciate any help!

 

I have a spreadsheet that looks this:

NameQuestion 1Question 2Question 3
John DoeYesYesNo
Jane SmithNoYesYes

 

How do I count the frequency for each column so the output looks like this:

 Question 1Question 2Question 3
Yes121
No101
4 REPLIES 4
Reeza
Super User

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

 

kc1895
Calcite | Level 5
What if I have col2, col3, etc. How do I combine it in the same table?
novinosrin
Tourmaline | Level 20

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
Reeza
Super User
Depends on how you want to combine them.
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1204 views
  • 0 likes
  • 3 in conversation