CALL RANBIN

# CALL RANBIN

Returns a random variate from a binomial distribution

 Category: Random Number

## Syntax

 CALL RANBIN(seed,n,p,x);

### Arguments

seed
is the seed value. For more information about seeds, see Seed Values. A new value for seed is returned each time CALL RANBIN is executed.
 Range: seed < 231 - 1 Note: If seed 0, the time of day is used to initialize the seed stream.

n
is an integer number of independent Bernoulli trials.
 Range: n > 0

p
is a numeric probability of success parameter.
 Range: 0

x
is a numeric SAS variable. A new value for the random variate x is returned each time CALL RANBIN is executed.

The CALL RANBIN routine updates seed and returns a variate x that is generated from a binomial distribution with mean np and variance np(1-p). If n 50, np 5, or n(1-p) 5, SAS uses an inverse transform method applied to a RANUNI uniform variate. If n>50, np>5, and n(1-p)>5, SAS uses the normal approximation to the binomial distribution. In that case, the Box-Muller transformation of RANUNI uniform variates is used.

By adjusting the seeds, you can force streams of variates to agree or disagree for some or all of the observations in the same, or in subsequent, DATA steps.

The CALL RANBIN routine gives greater control of the seed and random number streams than does the RANBIN function.

This example uses the CALL RANBIN routine:

```options nodate pageno=1 linesize=80 pagesize=60;

data case;
retain Seed_1 Seed_2 Seed_3 45;
n=2000;
p=.2;
do i=1 to 10;
call ranbin(Seed_1,n,p,X1);
call ranbin(Seed_2,n,p,X2);
X3=ranbin(Seed_3,n,p);
if i=5 then
do;
Seed_2=18;
Seed_3=18;
end;
output;
end;
run;

proc print;
id i;
var Seed_1-Seed_3 X1-X3;
run;```

The RANBIN Example shows the results.

The RANBIN Example
 ``` The SAS System 1 i Seed_1 Seed_2 Seed_3 X1 X2 X3 1 1404437564 1404437564 45 385 385 385 2 1445125588 1445125588 45 399 399 399 3 1326029789 1326029789 45 384 384 384 4 1988843719 1988843719 45 421 421 421 5 2137808851 18 18 430 430 430 6 1233028129 991271755 18 392 374 392 7 50049159 1437043694 18 424 384 424 8 802575599 959908645 18 371 383 371 9 100573943 1225034217 18 428 388 428 10 414117170 425626811 18 402 403 402```

Changing Seed_2 for the CALL RANBIN statement, when I=5, forces the stream of the variates for X2 to deviate from the stream of the variates for X1. Changing Seed_3 on the RANBIN function, however, has no effect.

 Function: