Returns a random variate from a gamma distribution
Category: Random Number
CALL RANGAM ( seed,a,x );
seed
is the seed value. A new value for seed is returned each time CALL RANGAM 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
a
is a numeric shape parameter.
Range: a > 0
x
is a numeric variable. A new value for the random variate x is returned each time CALL RANGAM is executed.
The CALL RANGAM routine updates seed and returns a variate x that is generated from a gamma distribution with parameter a .
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.
For a >1, an acceptance- rejection method by Cheng is used (Cheng, 1977; see in 'References' on page 926). For a 1, an acceptance-rejection method by Fishman is used (Fishman, 1978; see in 'References' on page 926).
The CALL RANGAM routine gives greater control of the seed and random number streams than does the RANGAM function.
This example uses the CALL RANGAM routine:
options nodate pageno=1 linesize=80 pagesize=60; data case; retain Seed_1 Seed_2 Seed_3 45; a=2; do i=1 to 10; call rangam(Seed_1,a,X1); call rangam(Seed_2,a,X2); X3=rangam(Seed_3,a); 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:
The SAS System 1 i Seed_1 Seed_2 Seed_3 X1 X2 X3 1 1404437564 1404437564 45 1.30569 1.30569 1.30569 2 1326029789 1326029789 45 1.87514 1.87514 1.87514 3 1988843719 1988843719 45 1.71597 1.71597 1.71597 4 50049159 50049159 45 1.59304 1.59304 1.59304 5 802575599 18 18 0.43342 0.43342 0.43342 6 100573943 991271755 18 1.11812 1.32646 1.11812 7 1986749826 1437043694 18 0.68415 0.88806 0.68415 8 52428589 959908645 18 1.62296 2.46091 1.62296 9 1216356463 1225034217 18 2.26455 4.06596 2.26455 10 805366679 425626811 18 2.16723 6.94703 2.16723
Changing Seed_2 for the CALL RANGAM 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 RANGAM function, however, has no effect.
Function:
'RANGAM Function' on page 777