CALL RANBIN Routine


Returns a random variate from a binomial distribution

Category: Random Number

Syntax

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

Arguments

seed

  • is the seed value. A new value for seed is returned each time CALL RANBIN is executed.

  • Range: seed < 2 31 -1

  • Note: If seed 0, the time of day is used to initialize the seed stream.

  • See: 'Seed Values' on page 257 for more information about seed values

n

  • is an integer number of independent Bernoulli trials.

  • Range: n > 0

p

  • is a numeric probability of success parameter.

  • Range: 0 < p < 1

x

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

Details

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.

Comparisons

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

Examples

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 following output shows the results:

Output 4.6: The RANBIN Example
start 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 
end example
 

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.

See Also

Function:

  • 'RANBIN Function' on page 764




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net