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!
DATA random;
DO i=1 to 100;
x = UNIFORM(123456);
IF x>.5 THEN coin = 'heads';
ELSE coin = 'tails';
OUTPUT;
END;
RUN;
PROC FREQ DATA=random;
table coin;
RUN;