/* Example code for finding hypergeometric probabilities in SAS */ OPTIONS pagesize=50 linesize=64; /* (setting the page margins) */ /* The command PROBHYPR computes _cumulative_ hypergeometric probabilities */ /* To get the cumulative probability, the syntax is: probhypr(N,r,n,x) */ /* where N, S, n, and x are values that you fill in */ /* Suppose our random variable X is hypergeometric with N=12, r=5, and n=4 (like in our class example). */ /* Let's answer the following questions */ /* 1. What is the probability of EXACTLY 2 successes? P(X = 2) */ /* 2. What is the probability of more than 2 successes? P(X > 2) */ /* 3. What is the probability of fewer than 2 successes? P(X < 2) */ /* 4. What is the probability of 2 or more successes? P(X >= 2) */ /* 5. What is the probability of 1, 2, or 3 successes? P(1 <= X <= 3) */ /* This SAS program will give us the answers to all these questions in an instant */ /* I will label the answers to the 5 questions as prob1, prob2, ... , prob5. */ data hyp; prob1=probhypr(12,5,4,2) - probhypr(12,5,4,1); /* P(X = 2) = P(X <= 2) - P(X <= 1) */ prob2= 1 - probhypr(12,5,4,2); /* P(X > 2) = 1 - P(X <= 2) */ prob3=probhypr(12,5,4,1); /* P(X < 2) = P(X <= 1) */ prob4= 1 - probhypr(12,5,4,1); /* P(X >= 2) = 1 - P(X <= 1) */ prob5=probhypr(12,5,4,3) - probhypr(12,5,4,0); /* P(1 <= X <= 3) = P(X <= 3) - P(X <= 0) */ run; proc print data=hyp; title 'Hypergeometric Probabilities'; run; /* After we input this program into the program editor and run the code */ /* Then the results print in the Output window */