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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1431 views
  • 0 likes
  • 2 in conversation