N/A
Posts: 1

# How to write the code for multinomial coefficients in SAS?

Within a larger SAS program, I wish to compute multinomial coefficients, say

\${y \choose a_1, a_2, \ldots, a_k}\$

and I can't figure out how to compute this value for a changing value k (ie changing number of terms, a1 through a_k). Any advice or suggestions that can be offered would be greatly appreciated. Thanks.
Valued Guide
Posts: 684

## Re: How to write the code for multinomial coefficients in SAS?

One approach is to take advantage of the fact that x! is the same as GAM(x+1), where GAM() is the complete gamma function. Also, note that the function can blow up with very large numbers, so it is better to work in log gamma functions, and then use exp() to retrieve the result. If one wanted to do the combinatorial "n choose y", one could use the following code. For instance, "10 choose 3" is 120.
data bb;
input n y;
C1 = (lgamma(n+1) -lgamma(y+1) - lgamma(n-y+1) );
C = exp(C1);
datalines;
5 0
5 1
5 2
5 3
5 4
5 5
10 0
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
10 10
1000 0
1000 500
1000 999
;
proc print data=bb;
run;
Discussion stats