BookmarkSubscribeRSS Feed
Obsidian | Level 7
(originally posted on SAS-L)


I am doing some very large binomial distribution simulations using ranbin in SAS 9.1.3 on Windows XP, and I'm interested in comparing notes with other ranbin users.

I have learned some interesting things about ranbin that I haven't seen in the documentation. It appears that the largest allowed value of N is (2**31 - 1). It appears that the smallest allowed value of p is around (1E-323). I've gotten errors outside these ranges.

In the documentation for ranbin it does say that the normal approximation with mean N*p and variance N*p*(1-p) is used when N > 50 and min(N*p,N*(1-p)) > 5. I have been getting very, very slow performance from ranbin. When I explicitly substitute rannor under the conditions given (N > 50 and min(N*p,N*(1-p)) > 5), I get similar (not identical) numerical results, but orders of magnitude faster. I am thinking of chucking ranbin altogether and just using a combination of rannor and ranpoi.

Has anyone else found such slow performance from ranbin? Any suggestions on how to handle it? Has anyone had a good experience with ranbin?


-- TMK --
t o p k a t z @ m s n . c o m
Obsidian | Level 7
I submitted this to SAS tech support (tracking number 7610166978) and got an excellent suggestion from tech support representative Phil Gibbs. The rand('BINOMIAL',p,n) function is much faster than ranbin(seed,n,p). Also, while rand has the same upper bound for n (2**31 - 1) as ranbin, it seems to work for any p between 0 and 1, whereas ranbin doesn't work at the extremes of p. Just note that if you want to control the seeding, you need to use call streaminit(seed).

This is issue #5 on my list, which applies to all of the old RAN*** functions in SAS:

Six reasons you should stop using the RANUNI function to generate random numbers - The DO Loop



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2 in conversation