# Help with SAS assignment - I do not know how to do this in SAS??

#### JessicaRLS

##### New Member
Study the notes “Simulations in SAS” and answer the questions that follow.
Questions
1. Draw 10000 values randomly from a standard normal population and determine the following probabilities empirically (that is through a simulation).
a) P(Z < 1.8), Z ~ N(0,1).
b) P(–1.024 < Z < 1.235)
Note: The rannor(seed) function generates a value randomly from the N(0,1) population.
The seed value can be any integer. If 0 is chosen the values generated will differ for each
simulation.

2. A man pays R10 to win a R30 Kewpie doll. His probability of winning on each throw is 0.3. He must win a doll for each of his five children. Let X be the random variable indicating the number of throws required to win five dolls. Determine through simulation empirical values for the following.
a) The probability that 10 throws are needed to win the five dolls, that is P(X = 10).
b) The probability that at least ten throws will be required, that is P(X ≥ 10).
c) The expected number of throws needed to win five dolls, that is E(X).
Note: The ranuni(seed) function generates a value randomly from the UNIF(0,1) population.
In this problem, a value in the interval [0,0.3] can be considered as winning on a throw.

*see attached for Notes&examples*

#### Dason

##### Ambassador to the humans
Hi! :welcome: We are glad that you posted here! This looks like a homework question though. Our homework help policy can be found here. We mainly just want to see what you have tried so far and that you have put some effort into the problem. I would also suggest checking out this thread for some guidelines on smart posting behavior that can help you get answers that are better much more quickly.

#### noetsi

##### No cake for spunky
I might be able to help after that occurs, although I use enterprise guide SAS

#### JessicaRLS

##### New Member
It is not a homework question, it is an old assignment I found, but we are writing an exam on this soon so I need to figure out this whole LOOP section! This is my attempt, I think Question 1(a) is correct, not sure about 1(b)? And I am mainly confused with question 2. Have no idea what is going on, PLEASE help:
-----------------------------------------------------
data question1a;
do j=1 to 10000;
z=rannor(0);
if z<1.8 then ind=1; else ind=0;
output;
end;

proc means n mean;
var z ind;
run;
-----------------------------------------------------
data question1b;
do j=1 to 10000;
z=rannor(0);
if (z>-1.024 AND z<1.235) then ind=1; else ind=0;
output;
end;

proc means n mean;
var z ind;
run;
-----------------------------------------------------
data question2;
throws=0;
do i=1 to 1000;
dolls=0;
do until (u<=0.3);
u=ranuni(0);
if u<=0.3 then dolls=dolls+1; else throws=throws+1;
output;
end;

proc print;
run;
-----------------------------------------------------

#### JessicaRLS

##### New Member
Thanks I just need to know if I'm on the right path or not and maybe you can explain what I'm doing wrong? I really don't get the whole loop thing, especially the 'do until' -_-

#### JessicaRLS

##### New Member
Hey thanks for the warm welcome! I have posted my efforts, not sure if I'm on the right track or not..

#### noetsi

##### No cake for spunky
I use the EG gui which does things automatically (commonly through macros) so I am not much help with code

#### chetan.apa

##### Member
Study the notes “Simulations in SAS” and answer the questions that follow.
Questions
1. Draw 10000 values randomly from a standard normal population and determine the following probabilities empirically (that is through a simulation).
a) P(Z < 1.8), Z ~ N(0,1).
b) P(–1.024 < Z < 1.235)
Note: The rannor(seed) function generates a value randomly from the N(0,1) population.
The seed value can be any integer. If 0 is chosen the values generated will differ for each
simulation.

2. A man pays R10 to win a R30 Kewpie doll. His probability of winning on each throw is 0.3. He must win a doll for each of his five children. Let X be the random variable indicating the number of throws required to win five dolls. Determine through simulation empirical values for the following.
a) The probability that 10 throws are needed to win the five dolls, that is P(X = 10).
b) The probability that at least ten throws will be required, that is P(X ≥ 10).
c) The expected number of throws needed to win five dolls, that is E(X).
Note: The ranuni(seed) function generates a value randomly from the UNIF(0,1) population.
In this problem, a value in the interval [0,0.3] can be considered as winning on a throw.

*see attached for Notes&examples*
May be its too later for help..but anyway
For 2(a)
P(X=10) means that what is the probability that he will get 5 dolls in 10 chances where each chance has probability 0.3 of getting a doll.
So you should run times simulation sufficient no. of times lets says 10000
For each simulation, there will be a loop running 10 times, inside the loop generate a uniform random variable and check if it is <0.3. If yes then increment no. of dolls.
Now, take cases where count is 5 and the last throw results in a doll.
Out of 10000, calculate the fraction of such cases, it will give you the required probability.