/* Example code for finding binomial probabilities in SAS */ OPTIONS pagesize=50 linesize=64; /* (setting the page margins) */ /* The command PROBBNML computes _cumulative_ binomial probabilities */ /* To get the cumulative probability, the syntax is: probbnml(p, n, x) */ /* where p, n, and x are values that you fill in */ /* Suppose our random variable X is binomial with n=20 and p=0.65 */ /* Let's answer the following questions */ /* 1. What is the probability of 13 or fewer successes? P(X <= 13) */ /* 2. What is the probability of 6 or fewer successes? P(X <= 6) */ /* 3. What is the probability of EXACTLY 13 successes? P(X = 13) */ /* 4. What is the probability of more than 13 successes? P(X > 13) */ /* 5. What is the probability of 13 or more successes? P(X >= 13) */ /* 6. What is the probability of 8, 9, or 10 successes? P(8 <= X <= 10) */ /* This SAS program will give us the answers to all these questions in an instant */ /* I will label the answers to the 6 questions as prob1, prob2, ... , prob6. */ data binom; prob1 = probbnml(0.65, 20, 13); prob2 = probbnml(0.65, 20, 6); prob3 = probbnml(0.65, 20, 13) - probbnml(0.65, 20, 12); prob4 = 1 - probbnml(0.65, 20, 13); prob5 = 1 - probbnml(0.65, 20, 12); prob6 = probbnml(0.65, 20, 10) - probbnml(0.65, 20, 7); run; proc print data=binom; title 'Binomial Probabilities'; run; /* After we input this program into the program editor and do "Run"->"Submit" */ /* Then the results print in the Output window */ /* Notice how the commands mirror the examples we did in class using the tables */ /* The difference is: SAS can do these for any n and p, whereas the table only */ /* gives probabilities for certain n and p choices. */