I am doing a poker simulation in SAS. So far I have created a deck, shuffled and dealt 5 card hands (no draw), and kept track of pairs, trips, 4 of a kind, and flushes using proc freq. Now I am trying to get SAS to recognize straights. I have assigned numerical values to the card ranks (2=2, J=11, A=14, etc.). My professor suggested using an Array to do this process and showed me a sample code. The first part is the code I am using where I assigned numerical values. The other data steps (data 1, 2, and 3) are the array. Could someone offer suggestions as to how I would use the array with the code I am using? %let decksize=52;
%let handsize=5;
%let nsims=10000;
%let nhands=5;
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";
if value="A" then numval=14;
else if value="2" then numval=2;
else if value="3" then numval=3;
else if value="4" then numval=4;
else if value="5" then numval=5;
else if value="6" then numval=6;
else if value="7" then numval=7;
else if value="8" then numval=8;
else if value="9" then numval=9;
else if value="T" then numval=10;
else if value="J" then numval=11;
else if value="Q" then numval=12;
else numval=13;
if suit="C" then suitval=1;
else if suit="D" then suitval=2;
else if suit="H" then suitval=3;
else suitval=4;
order=rand("uniform");
output;
end;
end;
run;
*Array commands shown by professor;
data one;
do i=2 to 6;
if i^=6 then cards=i;
else cards=6;
output;
end;
run;
data two;
set one;
array hand{5} c1-c5;
retain hand;
hand{_n_}=cards;
if _n_=5;
run;
data three;
set two;
straight=1;
array hand{5} c1-c5;
do i= 1 to 4;
if hand{i+1}-hand{i}^=1 then do;
card=i;
straight=0;
leave;
end;
end;
if card=4 then if hand{5}-hand{4}=9 then straight=1;
run; commands my professor showed me.
... View more