Random-number
functions and CALL routines generate streams of
random numbers from an initial starting point, called a seed, that either the user or the computer clock supplies. A seed must be a nonnegative integer with a
value less than 231-1 (or 2,147,483,647). If you use a positive seed, you
can always replicate the stream of random numbers by using the same DATA step.
If you use zero as the seed, the computer clock initializes the stream, and
the stream of random numbers is not replicable.

Each random-number function and CALL routine generates pseudo-random
numbers from a specific statistical distribution. Every random-number function
requires a seed value expressed as an integer constant or a variable that
contains the integer constant. Every CALL routine calls a variable that contains
the seed value. Additionally, every CALL routine requires a variable that
contains the generated random numbers.

The seed variable must be initialized prior to the first execution of
the function or CALL statement. After each execution of a function, the current
seed is updated internally, but the value of the seed argument remains unchanged.
After each iteration of the CALL statement, however, the seed variable contains
the current seed in the stream that generates the next random number. With
a function, it is not possible to control the seed values, and, therefore,
the random numbers after the initialization.

Comparison of Random-Number Functions and CALL Routines

Except for the NORMAL and UNIFORM functions, which are equivalent to
the RANNOR and RANUNI functions, respectively, SAS provides a CALL routine
that has the same name as each random-number function. Using CALL routines
gives you greater control over the seed values. As an illustration of this
control over seed values, all the random-number CALL routines show an example
of interrupting the stream of random numbers to change the seed value.

With a CALL routine, you can generate multiple streams of random numbers
within a single DATA step. If you supply a different seed value to initialize
each of the seed variables, the streams of the generated random numbers are
computationally independent. With a function, however, you cannot generate
more than one stream by supplying multiple seeds within a DATA step. The following
two examples illustrate the difference.

Examples

Example 1: Generating Multiple Streams from a CALL Routine

This example uses the CALL RANUNI routine to generate three streams
of random numbers from the uniform distribution with ten numbers each. See
the results in The CALL Routine Example.

Example 2: Assigning Values from a Single Stream to Multiple Variables

Using the same three seeds that were used in Example 1, this example
uses a function to create three variables. The results that are produced are
different from those in Example 1 because the values of all three variables
are generated by the first seed. When you use an individual function more
than once in a DATA step, the function accepts only the first seed value that
you supply and ignores the rest.

The Function Example
shows the results. The values of Y1, Y2, and Y3 in this example come from
the same random-number stream generated from the first seed. You can see this
by comparing the values by observation across these three variables with the
values of X1 in The CALL Routine Example.