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.
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;
What have you tried?
How to create a data-step version of your data
https://communities.sas.com/t5/help/faqpage/faq-category-id/posting#posting
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...
How to Add attachments
https://communities.sas.com/t5/Community-Memo/Adding-attachments-to-your-communities-posts/ba-p/4647...
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.