Help using Base SAS procedures

How to create a scale of number of responses to a group of variables

Reply
New Contributor
Posts: 4

How to create a scale of number of responses to a group of variables

Hello, 

 

I'm trying to create a new variable in a data set which would act as a scale reflecting the number of positive responses among a group of other variables.

 

So, there are 5 variables with categorical, binary responses (yes/no), and I want to make a new variable which would have 6 categorical responses which might be All Five, Four, Three, Two, One and None. For example, an observation with a 'Yes' response to 2 of the 5 variables would warrant a "Two" in my new variable. Three 'Yes's' would be a Three, and so on. 

 

Making the 'All 5' and 'None' is easy, and I know I could sort of use brute force and set up if-then statements for all the possible combinations for 2, 3, and 4, but I feel there may be a simpler and less error-prone way to go about this in a data statement. Any ideas?

 

Thank you in advance!

Trusted Advisor
Posts: 1,918

Re: How to create a scale of number of responses to a group of variables

If your binary variables named x1 through x5 are numeric and coded as 0 or 1, this is pretty easy.

 

newvariable=sum(of x1-x5);
Regular Contributor
Posts: 212

Re: How to create a scale of number of responses to a group of variables

[ Edited ]

Hi mate,

 

So you only need to make this new variable about the YES ?

Valued Guide
Posts: 765

Re: How to create a scale of number of responses to a group of variables

[ Edited ]

Hi, if you really want words ...

 

data x;
input x1-x5;
datalines;

. . . . .
0 0 0 0 0
1 0 0 0 0
1 1 0 0 0
1 1 1 0 0
1 1 1 1 0
1 1 1 1 1
;

 

data y;
set x;
score = upcase(put(sum(of x: ),words.));
run;

 

x1 x2 x3 x4 x5 score

 .  .  .  .  . MISSING

 0  0  0  0  0 ZERO
 1  0  0  0  0 ONE
 1  1  0  0  0 TWO
 1  1  1  0  0 THREE
 1  1  1  1  0 FOUR
 1  1  1  1  1 FIVE

Ask a Question
Discussion stats
  • 3 replies
  • 309 views
  • 2 likes
  • 4 in conversation