I am doing a coin toss simulation, simple enough (below is my code)
but I want to add one more step to it and not sure how do I go about it:
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.
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!
DO i=1 to 100;
x = UNIFORM(123456);
IF x>.5 THEN coin = 'heads';
ELSE coin = 'tails';
for the purpose of clarity, your challenge is perhaps in need of more sample input and output data.
Before working hard to simulate something that is delivered with a SAS function, have you looked at "Using Random-Number Functions" http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a001281561.htm ?
I think this is what I am looking for. Thank you so much!
I am still not good at interpreting things is SAS and I can't make out the results.
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
I will get 25 heads and 25 tails (in a perfect scenario)
out of the 25 tails I toss again
I will get 12.5 heads and 12.5 tail (lets say 12 heads and 13 Tail)
out of the 13 tail I toss again
I will get 6 heads and 7 tails ( rounded)
out of the 7 tails I toss again
I will get 3 heads and 4 tails
out of the 4 tails I toss again
I will get 2 heads and 2 tails
out of 2 tails I toss again
I get 1 head and one tails
if I count all the heads I will get
now lets count the tails
so at the end I still have almost a 1:1 ratio
is that what I should expect when I run your code?
Thanks again for all you help
Yes, that's what you can expect. You just would have to analyse the generated data appropriately (a simple Proc Freq won't do).
But.... What do you want to prove? That a SAS uniform distribution works as documented?
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.
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.
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?
Thank you Patrick!
Believe or not my degree is in Mathematics, but I find Statistics confusing!
I am not going to prove the algorithm, I just wanted a simple simulation of it.
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