BookmarkSubscribeRSS Feed
kfs
Calcite | Level 5 kfs
Calcite | Level 5
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.
1 REPLY 1
lvm
Rhodochrosite | Level 12 lvm
Rhodochrosite | Level 12
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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1557 views
  • 0 likes
  • 2 in conversation