Functions and CALL Routines |
Returns a random variate from a gamma distribution.
-
seed
-
is the seed value. A new value for seed is returned each time CALL RANGAM is executed.
-
a
-
is a numeric shape parameter.
-
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). For a
1, an acceptance-rejection method by Fishman is used (Fishman,
1978; see in References).
For a discussion and example of an effective use of the random number
CALL routines, see Starting, Stopping, and Restarting a Stream.
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 u1(keep=x);
seed = 104;
do i = 1 to 5;
call rangam(seed, x);
output;
end;
call symputx('seed', seed);
run;
data u2(keep=x);
seed = &seed;
do i = 1 to 5;
call rangam(seed, x);
output;
end;
run;
data all;
set u1 u2;
z = rangam(104);
run;
proc print label;
label x = 'Separate Streams' z = 'Single Stream';
run;
Output from the CALL RANGAM Routine
The SAS System 1
Separate Single
Obs Streams Stream
1 1.44347 1.44347
2 0.11740 0.11740
3 0.54175 0.54175
4 0.02280 0.02280
5 0.16645 0.16645
6 0.21711 0.21711
7 0.75538 0.75538
8 1.21760 1.21760
9 1.72273 1.72273
10 0.08021 0.08021
The RANGAM Example
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.
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.