BookmarkSubscribeRSS Feed
Eric1337
Calcite | Level 5
I am trying to create a variable that is dependent on responses to 3 other variables that is grouped under one main category in a survey.
If the respondent has responded yes ( which is coded as 1) to more than one of the three variables then , then this new variable is coded as 1
Or in other words the respondent must have responded yes to more than one of the three variables
Since all the three variables are numeric, I made a new variable in a data step that calculates the sum of these responses to the three variables .
If the sum is greater than 1 then this new variable is coded as 1 otherwise 0 .
This is just to determine the percent of this new variable . Just descriptive statistics
Wondering if anyone has any thoughts?
Thanks
3 REPLIES 3
PaigeMiller
Diamond | Level 26

Simple math. Add up the zeros and ones, if it is 2 or greater then new variable is 1.

 

Percent of 0/1 binary variables that are 1: use PROC SUMMARY and compute the mean of this new variable.

--
Paige Miller
Eric1337
Calcite | Level 5
Thanks you Paige
ballardw
Super User

Recode = ( sum(var1, var2, var3) > 1);

 

SAS will return 1/0 for true/false of comparisons. If the variables are all numeric coded 1/0 then sum is the number of 1 responses.

 

Caveat: the above will return 0 for the comparison if all the responses are missing. If you require that at least some number of the variables have an answer, such as 2 for example, then perhaps:

 

If n(var1,var2,var3)>2 then Recode = ( sum(var1, var2, var3) > 1);

Which will only assign a value to Recode when at least two of the variables have values.

 

If your variables have a common "root" name you can use short cut lists like  sum(of var: ) The : says to use all of the variables whose names start with VAR (caution).

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 519 views
  • 0 likes
  • 3 in conversation