BookmarkSubscribeRSS Feed
jloft12
Calcite | Level 5

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!

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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);
--
Paige Miller
DartRodrigo
Lapis Lazuli | Level 10

Hi mate,

 

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

MikeZdeb
Rhodochrosite | Level 12

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 2092 views
  • 2 likes
  • 4 in conversation