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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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