Date: Fri, 16 Feb 1996 11:58:47 -0500
Reply-To: "WEILER, R. BLAKE" <rbw.wilson@MHS.UNC.EDU>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: "WEILER, R. BLAKE" <rbw.wilson@MHS.UNC.EDU>
Organization: UNC
Subject: Multible random function calls
I just figured something out about the sas random number functions
which perhaps must others already know, but which cased me some amount of
problems. Apparently each random number function (RANUNI, RANNOR,
RANPOI, etc.) creates and uses its own seed value. Therefor, one must be
very careful about using different random number functions in the same
data step.
For example, in the following data step random Poisson variates, Y, are
generated and assigned to on of two groups based on the value of a
uniform variate. Both function calls are initialized with a negative
seed so that the time of day is used as the initial seed. Since the
initial seeds are the same and since the ranpoi function either calls the
ranuni function or uses the same routine, in each iteration the two seed
values are the same. Therefore high values of the Poisson variate occur
with high values of the uniform variate, and low values occur with low
values. The result of one run produced 5014 observations of Group A with
a mean of 7.487, and 4989 observations of Group B with a mean of 12.442;
data ONE;
do i=1 to 10000;
Y = ranpoi(-1, 10);
x = ranuni(-1);
if x<.5 then group = 'A';
else group = 'B';
output;
end;
The way around this is to use the random number call routines. But
even here one has to be careful not to use different seed variable for
the different routines (unless you specify an initial and different seed
for each rather then using the time of day) or else the same results
occurs. One must use a single seed variable for all random number call
routines used within a data step.
Just thought this might be useful.
---------------------------------------------
R. Blake Weiler
Curriculum in Ecology
CB# 3275, 299 Wilson Hall
Univ. of North Carolina
Chapel Hill, NC 27599-3275
rbw.wilson@mhs.unc.edu
919/962-5930
|