Help using Base SAS procedures

Combinations and permutations in sas

Super Contributor
Posts: 259

Combinations and permutations in sas

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.

Respected Advisor
Posts: 3,124

Re: Combinations and permutations in sas

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

data _null_;



     put comb=/ perm=;


Super User
Posts: 5,085

Re: Combinations and permutations in sas

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;


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};



drop i j k l m;


Creating COMBINATION is optional.

Super Contributor
Posts: 259

Re: Combinations and permutations in sas

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.

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation