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

Hi,

I have 3 variables and want to find all the possible combinations of two variables that satisfy a particular condition.

example:

t1  t2  t3

1  2   3

1  1   2

4  3   1

Condition: Sum of any two variable >=4. 

Answer: 1-->(2,3) 2-->() 3-->(4,3) (3,1) (4,1)

 

Kindly provide a solution using arrays,allcomb and other basic procedures if possible.

Thank You.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input t1  t2  t3 ;
cards;
1  2   3
1  1   2
4  3   1
;
data want;
 set have;
 id+1;
 array x{*} t1-t3;
 do i=1 to dim(x)-1; 
  do j=i+1 to dim(x);
    if sum(x{i},x{j})>=4 then do;want=cats('(',x{i},',',x{j},')');output;end;
  end;
 end;
 drop i j;
run;

View solution in original post

2 REPLIES 2
Ksharp
Super User
data have;
input t1  t2  t3 ;
cards;
1  2   3
1  1   2
4  3   1
;
data want;
 set have;
 id+1;
 array x{*} t1-t3;
 do i=1 to dim(x)-1; 
  do j=i+1 to dim(x);
    if sum(x{i},x{j})>=4 then do;want=cats('(',x{i},',',x{j},')');output;end;
  end;
 end;
 drop i j;
run;

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1359 views
  • 3 likes
  • 3 in conversation