CALL RANTBL Routine

Returns a random variate from a tabled probability distribution.

Category:Random Number
Note:Argument types for arguments that are updated must match in CALL routines. All argument types must be CHAR, VARCHAR, or NUMERIC. If the argument types do not match, a warning is issued to the log.

Syntax

CALL RANTBL(seed, p1, ...pi, ...pn, x);

Required Arguments

seed

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

Rangeseed < 231 – 1
NoteIf seed ≤ 0, the time of day is used to initialize the seed stream.
SeeConcepts and Pseudorandom Numbers

pi

is a numeric SAS value.

Range0 ≤ pi ≤ 1 for 0 < i ≤ n

x

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

Details

The CALL RANTBL routine updates seed and returns a variate x generated from the probability mass function defined by p1 through pn.

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 subsequent, DATA steps.

An inverse transform method applied to a RANUNI uniform variate is used. The CALL RANTBL routine returns this data:

table with 7 rows and 2 columns , row1 column 1 , , column 2 table with 1 row and 2 columns , row1 column 1 , 1 , column 2 w i t h p r o b eh b i l i t y , p sub 1 , end table , row2 column 1 , , column 2 table with 1 row and 2 columns , row1 column 1 , 2 , column 2 w i t h p r o b eh b i l i t y , p sub 2 , end table , row3 column 1 , , column 2 . , row4 column 1 , , column 2 . , row5 column 1 , , column 2 . , row6 column 1 , , column 2 table with 1 row and 2 columns , row1 column 1 , n , column 2 w i t h p r o b eh b i l i t y , p sub n , end table , row7 column 1 , , column 2 table with 1 row and 2 columns , row1 column 1 , n plus 1 , column 2 w i t h p r o b eh b i l i t y 1 minus . modified cap sigma with i equals 1 below and with n above . p sub i , i f . modified cap sigma with i equals 1 below and with n above . p sub i , less than or equal to 1 , end table . , end table. Click image for alternative formats.

If, for some index j<n,

table with 1 row and 1 column , row1 column 1 , modified cap sigma with i equals 1 below and with j above . p sub i , greater than or equal to 1 , end table. Click image for alternative formats.

RANTBL returns only the indices 1 through j, with the probability of occurrence of the index j equal to

table with 1 row and 1 column , row1 column 1 , 1 minus . modified cap sigma with i equals 1 below and with j minus 1 above . p sub i , end table. Click image for alternative formats.

For information about random number functions and CALL routines, see Using Random-Number Functions and CALL Routines in the DATA Step.

Comparisons

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

Example

This example uses the CALL RANTBL routine.

data u1(keep=x);
   seed=104;
   do i=1 to 5;
      call rantbl(seed, .02, x); 
      output;
   end;
   call symputx('seed', seed);
run;
data u2(keep=x);
   seed=&seed;
   do i=1 to 5;
      call rantbl(seed, .02, x); 
      output;
   end;
run;
data all;
   set u1 u2;
   z=rantbl(104, .02);
run;
proc print label;
   label x='Separate Streams' z='Single Stream';
run;

Output from the CALL RANTBL Routine

Output from the CALL RANTBL Routine

See Also

Last updated: April 14, 2026