BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aowusudommey
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Based on your incomplete explanation a statement like this may be helpful. 

combo6= (sum(of var1 - var8) = 6);

 

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

Forget SAS for a second. What is the logical rule that you are trying to program? Please explain.

--
Paige Miller
aowusudommey
Calcite | Level 5

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?

PaigeMiller
Diamond | Level 26

@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?

--
Paige Miller
aowusudommey
Calcite | Level 5

That is correct, each variable is assigned a value of either 1 or 0, there are no missing values. 

aowusudommey
Calcite | Level 5

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

SASKiwi
PROC Star

Based on your incomplete explanation a statement like this may be helpful. 

combo6= (sum(of var1 - var8) = 6);

 

aowusudommey
Calcite | Level 5

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. 

SASKiwi
PROC Star

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.

 

 

aowusudommey
Calcite | Level 5

You are absolutely correct, wow I cannot believe it was that simple. Thank you so much. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 889 views
  • 1 like
  • 3 in conversation