Help using Base SAS procedures

Poker Simulation

Reply
Occasional Contributor
Posts: 10

Poker Simulation

Im new to SAS and I am trying to do something fairly simple.  I want to create a deck of playing cards and shuffle that deck.  Then I want to produce 5 card poker hands and find the probabilities of producing certain hands (eg flush, straight flush, etc.)

Super User
Posts: 10,550

Re: Poker Simulation

With or without draw?

Or Texas Hold-em?

Or other version, Dr Pepper perhaps?

PROC Star
Posts: 554

Re: Poker Simulation

have you given any thought to what kind of poker is played or do you just want to draw 5 cards eg from a deck and see what hand you have?

Occasional Contributor
Posts: 10

Re: Poker Simulation

I am considering doing probabilities across different games. Perhaps run simulations using 5 card stud rules, 5 card (single draw), and seven card stud.
Super User
Posts: 9,691

Re: Poker Simulation

Calling @Rick_SAS

 

Check RANDPERK() in IML .

Check Rick's blog. there are many blogs about it .

SAS Super FREQ
Posts: 3,489

Re: Poker Simulation

Other references include

Simulate Blackjack: https://communities.sas.com/t5/SAS-IML-File-Exchange/Simulating-a-Blackjack-Game/ta-p/289668

and

Value of Poker Hands:https://communities.sas.com/t5/SAS-Procedures/Allocating-Values-to-Poker-Hands/m-p/146459#M38870

 

My personal view: This project is not particularly simple. If you are just looking for a project to get started in SAS, there are simpler simulations. For example, craps and blackjack have simpler rules. You can simulate craps in about 20-30 lines of SAS code. For a first project, you might even try to simulate a game related to flipping coins. Good luck!

 

 

 

 

Occasional Contributor
Posts: 10

Re: Poker Simulation

In our class, we created a deck and shuffled cards.  Then we did a very simplified poker game where we dealt five cards and kept track of only matching cards(e.g. pair, 3 of a kind and 4 of a kind).  I understand programming rules for the higher ranked hands (e.g. straight, flush, etc.) is a little trickier.  With that being said, I may forgo using five card draw rules so I can spend more time on creating code for the higher hands.  Then just do a simple 5 card and 7 card stud simulation i.e. no draws.  

I also considered doing a blackjack simulation but thought maybe some of the rules would be more complicated than a poker simulation.  I could be wrong.  

Occasional Contributor
Posts: 10

Re: Poker Simulation

Here is the code we used to create a standard 52 card deck.  We shuffled using proc sort and dealt a five card hand using proc surveryselect.  Finally, we used proc freq to keep track of "kind", i.e. one of a kind, two of a kind (pair), and three of a kind (trips).  Does anyone have suggestions on how to program SAS to find the frequency of the higher ranked hands (straights, flushes, royal flush, etc.)?

%let seed=1210; 
%let decksize=52;
%let handsize=5;
%let nsims=10;
%let nhands=1;

data _null_;
ncards=&handsize*&nhands;
call symput("ncards", ncards);
run;

data deck;
call streaminit(&seed);
do suit="C","D","H","S";
do value="2","3","4","5","6","7","8","9","T","J","Q","K","A";
order=rand("uniform");
output;
end;
end;
run;

proc sort data=deck;
by order;

/*proc print data=deck;
run;*/ 

proc surveyselect data=deck
method=srs
seed=&seed
sampsize=&ncards
rep=&nsims
out=cards;
run;

/*proc print data=cards;
run; */

/*data hands;
set cards;
hand=ceil(_n_/&handsize);
run;*/

/*proc print data=hands;
run;*/


proc freq data=cards;
tables value/out=freqval;
by replicate;
run;

/*proc print data=freqval;
run;*/

proc means data=freqval;
var count;
by replicate;
output out=maxnum max=kind;
run;

proc freq data=maxnum;
tables kind;
run;
Occasional Contributor
Posts: 10

Re: Poker Simulation

More specifically, does anyone have suggestions on how to program SAS to recognize straights using the code listed?
Ask a Question
Discussion stats
  • 9 replies
  • 291 views
  • 3 likes
  • 6 in conversation