Hi all,
I'm having an issue that I hope you can help with.
I have a very large dataset with multiple variables that I need to combine into various categories.
I've attempted this way:
IF (var1=1 and var2=1 and var3=1 and var4=1 and var5=1 and var6=1) OR
(var1=1 and var2=1 and var3=1 and var4=1 and var5=1 and var7=1) OR
(var1=1 and var2=1 and var3=1 and var4=1 and var5=1 and var8=1) OR
(var2=1 and var3=1 and var4=1 and var5=1 and var6=1 and var7=1) OR......
THEN combo6=1, else combo6=0
As you can see, this process has been tedious, and not very effective as the combinations i'm getting equal more than the data I have available. Does anyone have any idea how to accomplish this?
Based on your incomplete explanation a statement like this may be helpful.
combo6= (sum(of var1 - var8) = 6);
Forget SAS for a second. What is the logical rule that you are trying to program? Please explain.
Sure. The logic rule I'm attempting to follow is pretty simple, but hard to describe in text. Essentially, we have A, B, C, D, E, F, G, and H. What I need is all of the combinations of these letters in sets of 8, 7, 6, 5, and 4.
For example:
(A,B,C,D)=combo4
(B,C,D,E)=combo4
(C,D,E,F)=combo4
and so on.
However, the dataset given to me is categorical. I only want the variables that are "yes" (A=1, B=1, etc), included in the new variable.
8 is easy, but the remaining get complicated. Did that clarify at all?
@aowusudommey wrote:
Sure. The logic rule I'm attempting to follow is pretty simple, but hard to describe in text. Essentially, we have A, B, C, D, E, F, G, and H. What I need is all of the combinations of these letters in sets of 8, 7, 6, 5, and 4.
For example:
(A,B,C,D)=combo4
(B,C,D,E)=combo4
(C,D,E,F)=combo4
and so on.
However, the dataset given to me is categorical. I only want the variables that are "yes" (A=1, B=1, etc), included in the new variable.
8 is easy, but the remaining get complicated. Did that clarify at all?
May we assume that if A is not equal to 1, then it must be zero?
That is correct, each variable is assigned a value of either 1 or 0, there are no missing values.
So sorry, I should further explain that I would need any variable in the string that is equal 0 to cause the entire row to be equal to zero.
For example
(A=1 and B=1 and C=1 and D=1), then combo4=1
However:
(A=1 and B=1 and C=1 and D=0) then combo4=0
Based on your incomplete explanation a statement like this may be helpful.
combo6= (sum(of var1 - var8) = 6);
I am unfortunately not looking for a sum, I'm looking to have every possible combination of these 8 binary variables to be assigned to a new variable. So that, for example, every combination of 6 of the 8 variables would equal combo6, every combination of 5 of the 8 variables would equal combo5, and so on. I'm very sorry, I am not able to give exact information without violating a privacy agreement.
But summing any combination of 8 binary variables where the total is 6 will give you one of your answers - combo6?
var1 = 1 plus var2 = 1 plus var3 = 1 plus var4 = 1 plus var5 = 1 plus var6 = 1 equals 6.
You are absolutely correct, wow I cannot believe it was that simple. Thank you so much.
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!
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.