<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: BlackJack Probabilities in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/BlackJack-Probabilities/m-p/977910#M49047</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299716"&gt;@genemroz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I intended to select Rick Wicklin's solution as "Accepted" but clicked the wrong one.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299716"&gt;@genemroz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can correct that easily:&lt;BR /&gt;Select Rick's post&amp;nbsp;as the solution after clicking&amp;nbsp;"Not the Solution" in the option menu (see icon below) of the current solution.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="show_option_menu.png" style="width: 155px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110983iD45416D15D968D75/image-size/large?v=v2&amp;amp;px=999" role="button" title="show_option_menu.png" alt="show_option_menu.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Oct 2025 17:23:03 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2025-10-27T17:23:03Z</dc:date>
    <item>
      <title>BlackJack Probabilities</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/BlackJack-Probabilities/m-p/977825#M49041</link>
      <description>&lt;P&gt;How can a blackjack player be assured that the deck is honest?&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;If someone has replaced a random card in the deck with, say, an Ace,&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;How many hands would you have to play and how many aces would he have to see and count to be confident that the deck was altered? &lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I started with Rick Wicklin’s blog post on creating, shuffling and randomly dealing a standard deck of 52 cards.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;Then I created a black jack deck of 6x52 cards.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;I calculated the binomial probability of drawing at least one ace from any number of deals.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;I used Proc Freq to count the number of Aces that result from these deals. &lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;I did the same with an altered deck where I replaced the 2 of Clubs with an Ace of Clubs.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I don’t know how to get to the core question:&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;How many deals of the altered deck would it take for a player to be, say,&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;90% confident that there were too many aces in it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I’ve attached the code that I developed so far to address this question.&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;I hope someone can bring some insight into how it can be modified to address the question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for any guidance you can provide,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Gene&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create one deck of cards */
data Cards;
length Value $2 Suit $8 Card $3;
array Values[13] $ _temporary_ ('A','2','3','4','5','6','7','8','9','T','J','Q','K');
array Suits[4] $ _temporary_ ('Clubs', 'Diamonds', 'Hearts', 'Spades');
do v = 1 to 13;
   do s = 1 to 4;
      Value = Values[v]; Suit = Suits[s]; Card = cats(Value,substr(Suit,1,1));
      output;
   end;
end;
run;

/*For BlackJack we need 6 Decks  */
data work.Deck1 work.Deck2 work.Deck3 work.Deck4 work.Deck5 work.Deck6;
set Cards;
run;

data work.HonestBlackJackDeck;
set work.Deck1 work.Deck2 work.Deck3 work.Deck4 work.Deck5 work.Deck6;
run;

/*Create an altered BlackJackDeck by replacing one 2 of Clubs with an Ace of Clubs   */

Proc sort data=HonestBlackJackDeck;
by v s;
run;

data work.AlteredBlackJackDeck;
set HonestBlackJackDeck;
By v;
if first.v and v=2 then do;
Value='A';
Suit="Clubs";
Card='AC';
v=1;
s=1;
end;
run;


/*Set number of cards per player  */
%Let nCards=2;
/*Set number of players  */
%Let nPlayers=1;
/*Set number of deals  */
%Let nDeals=100;


/* HONEST BLACK JACK DECK */

/* Standard deviation of expected frequency of drawing at least one ace
in an honest Black Jack Deck */

data _null_;
Title "Binomial Distribution Calculations: Honest Black Jack Deck";
File Print;
Ctot=(312*311)/(2*1);
Put "Number of possible hands:  " Ctot;
/*Hands with no aces  */
CnoA=(312-24)*(312-24-1)/(2*1);
Put "Number of hands with no aces:  " CnoA;
/*Probability of no aces */
PnoA=CnoA/Ctot;
Put "Probability of no aces:  " PnoA;
/*Probability of at least one ace  */
PA=1-PnoA;
Put "Probability of at least 1 ace:  " PA;
/* Expected number of hands with at least 1 ace */
Ndeals=&amp;amp;ndeals;
Put "Number of Deals:  " Ndeals;
Expect=&amp;amp;nDeals*PA;
Put "Expected number of hands with at least 1 ace: " Expect;
/* Standard Deviation of a Binomial Distribution */
sigma=sqrt(&amp;amp;nDeals*PA*PnoA);
Put "Standard deviation of hands with of at least 1 ace:  " sigma;
/* 90% Confidence Interval */
CI90=1.645*(sigma/sqrt(ndeals));
Put "90% Confidence Interval:  " CI90;

Prob_LE_PA=cdf('binom',Expect,PA,&amp;amp;nDeals);
Put "Probability of less than expected hands with ace:  " Prob_LE_PA;
Prob_GE_PA=1-Prob_LE_PA;
Put "Probability of greater than expected hands with ace:  " Prob_GE_PA;

run;

/* Wicklin code for creating Black Jack Deals */
proc surveyselect data=HonestBlackJackDeck seed=123 NOPRINT
     method=SRS                   /* sample without replacement */
     outrandom                    /* randomize the order of the cards */
     N=%eval(&amp;amp;nCards * &amp;amp;nPlayers) /* num cards per deal */
     reps=&amp;amp;nDeals                 /* total number of deals */
     out=AllCards_HonestDeck;
run;

/* assign the cards to players */
data AllDeals_HonestDeck;
set AllCards_HonestDeck;
by Replicate;
if first.Replicate then do;
   Cnt = 0;
end;
Player = 1 + floor(Cnt/&amp;amp;nCards);
Cnt + 1;
drop Cnt;
run;

/* OPTIONAL: Convert from long form to wide form */
proc transpose data=AllDeals_HonestDeck 
               out=HonestDeals(rename=(col1-col&amp;amp;nCards=C1-C&amp;amp;nCards) drop=_NAME_);
   var Card;
   by Replicate Player;
run;

/* Check for an honest deck */
Proc freq data=HonestBlackJackDeck;
Title "Honest Black Jack Deck";
tables value;
run;

/* Find number of deals that contain aces */
Proc freq data=AllDeals_HonestDeck;
Title1 "Honest Black Jack Deck:";
Title2 "Number of deals that contain at least one ace";
where value contains 'A';
tables value /outexpect;


/* ALTERED BLACK JACK DECK */
/*(1 extra Ace of Clubs replacing a 2 of Clubs) */

/* Standard deviation of expected frequency of drawing at least one ace
in an altered Black Jack Deck */

data _null_;
Title1 "Binomial Distribution Calculations: Altered Black Jack Deck";
Title2 "After Substituting an Ace of Clubs for a Deuce of Clubs";
File Print;
Ctot=(312*311)/(2*1);
Put "Number of possible hands:  " Ctot;
/*Hands with no aces after substituting and ace for a deuce for a total of 25 aces  */
CnoA=(312-25)*(312-25-1)/(2*1);
Put "Number of hands with no aces:  " CnoA;
/*Probability of no aces */
PnoA=CnoA/Ctot;
Put "Probability of no aces:  " PnoA;
/*Probability of at least one ace  */
PA=1-PnoA;
Put "Probability of at least 1 ace:  " PA;
/* Expected number of hands with at least 1 ace */
Ndeals=&amp;amp;ndeals;
Put "Number of Deals:  " Ndeals;
Expect=&amp;amp;nDeals*PA;
Put "Expected number of hands with at least 1 ace: " Expect;
/* Standard Deviation of a Binomial Distribution */
sigma=sqrt(&amp;amp;nDeals*PA*PnoA);
Put "Standard deviation of hands with of at least 1 ace:  " sigma;
/* 90% Confidence Interval */
CI90=1.645*(sigma/sqrt(ndeals));
Put "90% Confidence Interval:  " CI90;
run;


proc surveyselect data=AlteredBlackJackDeck seed=123 NOPRINT
     method=SRS                   /* sample without replacement */
     outrandom                    /* randomize the order of the cards */
     N=%eval(&amp;amp;nCards * &amp;amp;nPlayers) /* num cards per deal */
     reps=&amp;amp;nDeals                 /* total number of deals */
     out=AllCards_AlteredDeck;
run;

/* assign the cards to players */
data AllDeals_AlteredDeck;
set AllCards_AlteredDeck;
by Replicate;
if first.Replicate then do;
   Cnt = 0;
end;
Player = 1 + floor(Cnt/&amp;amp;nCards);
Cnt + 1;
drop Cnt;
run;

/* OPTIONAL: Convert from long form to wide form */
proc transpose data=AllDeals_AlteredDeck 
               out=AlteredDeals(rename=(col1-col&amp;amp;nCards=C1-C&amp;amp;nCards) drop=_NAME_);
   var Card;
   by Replicate Player;
run;

/* Check for an honest deck */
Proc freq data=AlteredBlackJackDeck;
Title "Altered Black Jack Deck (1 extra Ace of Clubs replacing a 2 of Clubs)";
tables value;
run;

/* Find number of deals that contain aces */
Proc freq data=AllDeals_AlteredDeck;
Title "Altered Black Jack Deck";
Title2 "Number of deals that contain at least one ace";
where value contains 'A';
tables value /outexpect;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Oct 2025 17:00:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/BlackJack-Probabilities/m-p/977825#M49041</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2025-10-26T17:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: BlackJack Probabilities</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/BlackJack-Probabilities/m-p/977863#M49042</link>
      <description>It is about data simulation .&lt;BR /&gt;Calling &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;</description>
      <pubDate>Mon, 27 Oct 2025 06:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/BlackJack-Probabilities/m-p/977863#M49042</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-10-27T06:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: BlackJack Probabilities</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/BlackJack-Probabilities/m-p/977875#M49043</link>
      <description>&lt;P&gt;In practice, the subterfuge would be recognized the first time that a hand appears that shows two Ace of clubs. This will happen frequently, at which point you are 100% sure that the deck is altered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In terms of the simulation, your situation is equivalent to using a deck of 52 numbers that look like this:&lt;/P&gt;
&lt;P&gt;{1,1,2,3,4,6,7,8,...,52}, where '1'=AC and '5'=2C.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to stick with your original problem, which estimates frequencies, I suggest you start with a smaller deck for which the simulation will run faster and for which the probabilities are larger. For example, start with a deck of 8 cards (Aces and Twos) that look like&lt;/P&gt;
&lt;P&gt;{1,1,2,3,4,6,7,8}.&lt;BR /&gt;Figure out the answer to your problem with this smaller deck. When you can solve the problem with a deck that has 8 cards, test your knowledge by moving to a deck that has 12 cards. Then try 16. Then you will be ready for 52.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like your problem is related to using simulation to estimate "power and sample size."&amp;nbsp; See these articles:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/iml/2020/02/03/what-sample-size-do-you-need-for-a-binomial-test-of-proportions.html" target="_blank"&gt;What sample size do you need for a binomial test of proportions? - The DO Loop&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/iml/2021/04/05/sample-size-monte-carlo-integral.html" target="_blank"&gt;Sample size for the Monte Carlo estimate of an integral - The DO Loop&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/iml/2020/08/12/simulation-estimate-power-of-test.html" target="_blank"&gt;Use simulation to estimate the power of a statistical test - The DO Loop&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Oct 2025 10:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/BlackJack-Probabilities/m-p/977875#M49043</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2025-10-27T10:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: BlackJack Probabilities</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/BlackJack-Probabilities/m-p/977903#M49046</link>
      <description>&lt;P&gt;Well, dang...I intended to select Rick Wicklin's solution as "Accepted" but clicked the wrong one. &amp;nbsp;The link to Rick's blog post on sample size for a binomial test of proportions was most helpful. &amp;nbsp;As he found in the example he used there to determine how many students would be needed for a meaningful test, the number of blackjack hands that would have to be dealt is much larger than one might intuitively think.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll also take this opportunity to thank Rick Wicklin for his DO Loop blog. &amp;nbsp;I've lost count of the number of times I've Googled a question about a SAS statistical approach or a SAS Procedure and been directed to one of his always helpful posts. &amp;nbsp;This is but one more example of the value of the DO Loop.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Oct 2025 16:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/BlackJack-Probabilities/m-p/977903#M49046</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2025-10-27T16:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: BlackJack Probabilities</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/BlackJack-Probabilities/m-p/977910#M49047</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299716"&gt;@genemroz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I intended to select Rick Wicklin's solution as "Accepted" but clicked the wrong one.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/299716"&gt;@genemroz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can correct that easily:&lt;BR /&gt;Select Rick's post&amp;nbsp;as the solution after clicking&amp;nbsp;"Not the Solution" in the option menu (see icon below) of the current solution.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="show_option_menu.png" style="width: 155px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110983iD45416D15D968D75/image-size/large?v=v2&amp;amp;px=999" role="button" title="show_option_menu.png" alt="show_option_menu.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Oct 2025 17:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/BlackJack-Probabilities/m-p/977910#M49047</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-10-27T17:23:03Z</dc:date>
    </item>
  </channel>
</rss>

