BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8

I'm trying to generate code that takes 7 playing cards and generates every combination of 5 cards from those 7. Is there a simple way to do this? I think there are 42 different combinations.

3 REPLIES 3
Haikuo
Onyx | Level 15

Combination is 21. Permutation a lot big number, as order matters. Check out corresponding the SAS functions .

data _null_;

     comb=comb(7,5);

     perm=perm(7,5);

     put comb=/ perm=;

run;

Astounding
PROC Star

I would expect you will find 21 combinations, rather than 42.  Omitting card #3 and card #5 is identical to omitting card #5 and card #3.

The logic is similar to your earlier question, but the syntax is more complex.  More important, you have to picture what you would like the output to look like.  This approach creates 21 observations for each incoming observation:

data want;

set have;

combination=0;

array cards {7} hand1 hand2 flop1 flop2 flop3 turn river;

do i=1 to 3;

   do j=i+1 to 4;

      do k=j+1 to 5;
         do l=k+1 to 6;

            do m=l+1 to 7;

combination + 1;

card1 = cards{i};

card2 = cards{j};

card3 = cards{k};

card4 = cards{l};

card5 = cards{m};

output;

end;end;end;end;end;

drop i j k l m;

run;

Creating COMBINATION is optional.

brophymj
Quartz | Level 8

Thank you very much Astounding - that's very helpful as was your earliers advice to my other questions. Do you play cards? Seem to know your stuff.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1345 views
  • 2 likes
  • 3 in conversation