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.)
With or without draw?
Or Texas Hold-em?
Or other version, Dr Pepper perhaps?
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?
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!
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.
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;
Recognizing straights:
Rick_SAS,
I am interested to view the blackjack reference you provided however I am unable to view as it states access denied--You do not have sufficient privileges for this resource or its parent to perform this action. Could you please DM or share another way. Thank you.
Both of Rick's link work fine for me. Are both not working?
You may need to try a different computer.
The first link (blackjack) doesn't work. The second link works fine for me.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.