BookmarkSubscribeRSS Feed
jeffgreen
Fluorite | Level 6
Hi everyone,
I have created the following dataset:
 
data binomial;
input n p;
cards;
12 .5
9 .4
15 .6
;
run;
 
 
Thanks in advance
 
 
4 REPLIES 4
SASJedi
SAS Super FREQ
I moved this post to the Statistical Procedures forum, where it should get noticed by folks more familiar with topics like this.
Check out my Jedi SAS Tricks for SAS Users
FreelanceReinh
Jade | Level 19

Hi @jeffgreen,

 

Try this:

data want;
call streaminit(27182818);
set binomial;
k=n*p;
do r=1 by 1 until(k=0 | k=n);
  k=rand('binom',k/n,n);
  output;
end;
run;

If you don't need the individual binomial random numbers in dataset WANT, just omit the OUTPUT statement. Then you'll get only the final random number k (equal to 0 or n) and the number r of random number generations which led to this result.

jeffgreen
Fluorite | Level 6
Thank you so much!! Worked perfectly!
ballardw
Super User

@jeffgreen wrote:

Hi everyone,

I have created the following dataset:

 

data binomial;
input n p;
cards;
12 .5
9 .4
15 .6
;
run;

 

Basically, I want to run a Wright-Fisher simulation. For example, in the first line of code, I want to run binomial(12, .5), and using this result (say for example the result was 5), I want to do another binomial calculation- binomial (12, 5/12) where 5/12 is the result of the previous binomial simulation divided by n (12). I want to create code that, for each line of code, will repeat this until the generated number is 0 or n (which means the binomial simulation is either a success 0% of the time or 100% of the time). How would I go about doing this?

 

Thanks in advance

 

 


Please describe in some detail what this phrase means: " I want to run binomial(12, .5)".

SAS  provides a number of functions that will let you work with specified distributions like binomial with given parameters: CDF PDF PROBBNML but "run" does not describe much.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 794 views
  • 2 likes
  • 4 in conversation