<?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: Coin Toss Problem in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18130#M3523</link>
    <description>No, I don't even know what that is, I will look it up. Thanks&lt;BR /&gt;
Any help would be appreciate it!</description>
    <pubDate>Tue, 17 Nov 2009 20:07:47 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-11-17T20:07:47Z</dc:date>
    <item>
      <title>Coin Toss Problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18126#M3519</link>
      <description>I am doing a coin toss simulation, simple enough (below is my code) &lt;BR /&gt;
but I want to add one more step to it and not sure how do I go about it:&lt;BR /&gt;
If I get Heads, I stop, but if I get a Tail, I toss again, if I get a head I stop, but again if I get a tail I toss again......I keep tossing until I get a head, then I add up all the times I get a head and all the tails.&lt;BR /&gt;
I guess I need a macro and another while loop, but I can't seem to get it, any help would be greatly appreciated. THANKS!&lt;BR /&gt;
&lt;BR /&gt;
DATA random;&lt;BR /&gt;
  DO i=1 to 100;&lt;BR /&gt;
    x = UNIFORM(123456);&lt;BR /&gt;
    IF x&amp;gt;.5 THEN coin = 'heads';&lt;BR /&gt;
      ELSE coin = 'tails';&lt;BR /&gt;
    OUTPUT;&lt;BR /&gt;
  END;&lt;BR /&gt;
RUN;&lt;BR /&gt;
 &lt;BR /&gt;
PROC FREQ DATA=random;&lt;BR /&gt;
  table coin;&lt;BR /&gt;
RUN;</description>
      <pubDate>Tue, 17 Nov 2009 14:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18126#M3519</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-17T14:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Coin Toss Problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18127#M3520</link>
      <description>for the purpose of clarity, your challenge is perhaps in need of more sample input and output data.&lt;BR /&gt;
Before working hard to simulate something that is delivered with a SAS function, have you looked at &lt;B&gt;"Using Random-Number Functions" &lt;/B&gt;http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001281561.htm ?&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 17 Nov 2009 15:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18127#M3520</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-11-17T15:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: Coin Toss Problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18128#M3521</link>
      <description>I am using Random numbers, I made few changes but still not right, any help???&lt;BR /&gt;
Thanks in advance!&lt;BR /&gt;
&lt;BR /&gt;
data coin; &lt;BR /&gt;
&lt;BR /&gt;
Headcount=0;&lt;BR /&gt;
Tailcount=0; &lt;BR /&gt;
&lt;BR /&gt;
do k=1 to 1000;        /*do it 1000 times*/                                &lt;BR /&gt;
&lt;BR /&gt;
c = 0;                   /* this is to reset the loop if I get tail*/&lt;BR /&gt;
do while (c = 0); &lt;BR /&gt;
&lt;BR /&gt;
     do i = 1 to 100;                                        &lt;BR /&gt;
      x = ranuni (-3);      /*generate randon number*/&lt;BR /&gt;
	  IF x&amp;gt;.5 THEN do;&lt;BR /&gt;
HeadCount = HeadCount+1;&lt;BR /&gt;
 c = 1; &lt;BR /&gt;
&lt;BR /&gt;
 OUTPUT;&lt;BR /&gt;
 end;&lt;BR /&gt;
      else do;&lt;BR /&gt;
TailCount=TailCount+1;&lt;BR /&gt;
	  c=0;&lt;BR /&gt;
	  end;                                 &lt;BR /&gt;
&lt;BR /&gt;
     &lt;BR /&gt;
     end; &lt;BR /&gt;
  end; &lt;BR /&gt;
&lt;BR /&gt;
  output; &lt;BR /&gt;
  file print ;&lt;BR /&gt;
  put 'Number of Heads=' HeadCount;&lt;BR /&gt;
  put 'Number of Tail=' TailCount;&lt;BR /&gt;
&lt;BR /&gt;
end;</description>
      <pubDate>Tue, 17 Nov 2009 15:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18128#M3521</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-17T15:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Coin Toss Problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18129#M3522</link>
      <description>have you tried do while ('tail condition') loop?</description>
      <pubDate>Tue, 17 Nov 2009 17:27:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18129#M3522</guid>
      <dc:creator>abdullala</dc:creator>
      <dc:date>2009-11-17T17:27:04Z</dc:date>
    </item>
    <item>
      <title>Re: Coin Toss Problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18130#M3523</link>
      <description>No, I don't even know what that is, I will look it up. Thanks&lt;BR /&gt;
Any help would be appreciate it!</description>
      <pubDate>Tue, 17 Nov 2009 20:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18130#M3523</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-17T20:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Coin Toss Problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18131#M3524</link>
      <description>Are you after something like the following?&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
	value HeadTail&lt;BR /&gt;
		low - 0.5   = 'Tail'&lt;BR /&gt;
		0.5 &amp;lt;- high = 'Head'&lt;BR /&gt;
	;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
DATA random;&lt;BR /&gt;
format coin HeadTail.;&lt;BR /&gt;
DO group=1 to 100;&lt;BR /&gt;
toss=1;&lt;BR /&gt;
coin = UNIFORM(123456);&lt;BR /&gt;
do until (coin&amp;gt;.5);&lt;BR /&gt;
output;&lt;BR /&gt;
coin = UNIFORM(123456);&lt;BR /&gt;
toss+1;&lt;BR /&gt;
end;	&lt;BR /&gt;
END;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
PROC FREQ DATA=random;&lt;BR /&gt;
table group*coin;&lt;BR /&gt;
RUN;</description>
      <pubDate>Wed, 18 Nov 2009 00:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18131#M3524</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-11-18T00:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Coin Toss Problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18132#M3525</link>
      <description>I think this is what I am looking for. Thank you so much! &lt;BR /&gt;
I am still not good at interpreting things is SAS and I can't make out the results.&lt;BR /&gt;
&lt;BR /&gt;
What I am trying to prove is that at the end you have the same (almost) number of tails and heads. Lets say I start with 50 coins&lt;BR /&gt;
I will get 25 heads and 25 tails (in a perfect scenario)&lt;BR /&gt;
out of the 25 tails I toss again&lt;BR /&gt;
I will get 12.5 heads and 12.5 tail (lets say 12 heads and 13 Tail)&lt;BR /&gt;
out of the 13 tail I toss again&lt;BR /&gt;
I will get 6 heads and 7 tails ( rounded)&lt;BR /&gt;
out of the 7 tails I toss again&lt;BR /&gt;
I will get 3 heads and 4 tails&lt;BR /&gt;
out of the 4 tails I toss again&lt;BR /&gt;
I will get 2 heads and 2 tails&lt;BR /&gt;
out of 2 tails I toss again&lt;BR /&gt;
I get 1 head and one tails&lt;BR /&gt;
if I count all the heads I will get&lt;BR /&gt;
25+12+6+3+2+1=49&lt;BR /&gt;
now lets count the tails&lt;BR /&gt;
25+13+7+4+2+1=52&lt;BR /&gt;
so at the end I still have almost a 1:1 ratio &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
is that what I should expect when I run your code?&lt;BR /&gt;
Thanks again for all you help</description>
      <pubDate>Wed, 18 Nov 2009 02:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18132#M3525</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-18T02:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Coin Toss Problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18133#M3526</link>
      <description>Yes, that's what you can expect. You just would have to analyse the generated data appropriately (a simple Proc Freq won't do).&lt;BR /&gt;
&lt;BR /&gt;
But.... What do you want to prove? That a SAS uniform distribution works as documented? &lt;BR /&gt;
In the end SAS also uses only a mathematical algorithm to generate the random numbers - and I assume you'll find this algorithm documented... somewhere.&lt;BR /&gt;
&lt;BR /&gt;
So: If you want to prove something then it would be a mathematical approach proofing that the algorithm used is correct and an empirical proof showing that SAS really uses the algorithm as documented.&lt;BR /&gt;
&lt;BR /&gt;
And because it's about random numbers with no dependencies: Just generate a lot of observations and look at the distribution – no point to analyse sub-groups. It’s always the same probability so what do you expect?</description>
      <pubDate>Wed, 18 Nov 2009 04:00:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18133#M3526</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-11-18T04:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Coin Toss Problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18134#M3527</link>
      <description>Thank you Patrick!&lt;BR /&gt;
Believe or not my degree is in Mathematics, but I find Statistics confusing!&lt;BR /&gt;
I am not going to prove the algorithm, I just wanted a simple simulation of it.&lt;BR /&gt;
I have been trying to learn SAS for the past 2 months and I am in a love/hate relationship; while some days I can code easily, other days I find myself stuck and not really knowing where to start. So thank you so much for your help, I really do appreciate it</description>
      <pubDate>Wed, 18 Nov 2009 15:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18134#M3527</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-18T15:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Coin Toss Problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18135#M3528</link>
      <description>Interestingly, we don't get 50% at all, we get 75%-25%.&lt;BR /&gt;
&lt;BR /&gt;
That's because the last draw (that stops the loop) is not saved. So each time we have to redraw (1 out of 2 times), we don't save the final head.&lt;BR /&gt;
&lt;BR /&gt;
This might be better:&lt;BR /&gt;
&lt;BR /&gt;
DATA random;&lt;BR /&gt;
format coin HeadTail.;&lt;BR /&gt;
do group=1 to 1000;&lt;BR /&gt;
  toss=1;&lt;BR /&gt;
  do until (coin&amp;gt;.5);&lt;BR /&gt;
    coin = ranuni(0);&lt;BR /&gt;
    output;&lt;BR /&gt;
    toss+1;&lt;BR /&gt;
  end; &lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
PROC FREQ DATA=random;&lt;BR /&gt;
table coin;&lt;BR /&gt;
RUN;</description>
      <pubDate>Thu, 26 Nov 2009 21:49:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Coin-Toss-Problem/m-p/18135#M3528</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-11-26T21:49:39Z</dc:date>
    </item>
  </channel>
</rss>

