Chapter Contents

Previous

Next
CALL RANTBL

CALL RANTBL



Returns a random variate from a tabled probability distribution

Category: Random Number


Syntax
Arguments
Details
Comparisons
Examples
See Also

Syntax

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

Arguments

seed
is the seed value. For more information about seeds, see Seed Values. A new value for seed is returned each time CALL RANTBL is executed.
Range: seed < 231 - 1
Note: If seed [le] 0, the time of day is used to initialize the seed stream.

pi
is a numeric SAS value.
Range: 0 [IMAGE]pi [IMAGE]1 for 0< i [IMAGE]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 in subsequent, DATA steps.

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

[IMAGE]

If, for some index j<n,

[IMAGE]

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

[IMAGE]


Comparisons

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


Examples

This example uses the CALL RANTBL routine:

options nodate pageno=1 linesize=80 pagesize=60;  

data case;
    retain Seed_1 Seed_2 Seed_3 45;
    input p1-p9;
    do i=1 to 10;
       call rantbl(Seed_1,of p1-p9,X1);
       call rantbl(Seed_2,of p1-p9,X2);
       X3=rantbl(Seed_3,of p1-p9);
       if i=5 then
          do;
             Seed_2=18;
             Seed_3=18;
          end;
       output;
    end;
    datalines;
.02 .04 .06 .08 .1 .12 .14 .16 .18
;

proc print;
   id i;
   var Seed_1-Seed_3 X1-X3;
run;

The RANTBL Example shows the results.

The RANTBL Example
                                 The SAS System                                1
            i      Seed_1          Seed_2    Seed_3    X1    X2    X3

            1     694315054     694315054      45       6     6     6
            2    1404437564    1404437564      45       8     8     8
            3    2130505156    2130505156      45      10    10    10
            4    1445125588    1445125588      45       8     8     8
            5    1013861398            18      18       7     7     7
            6    1326029789     707222751      18       8     6     8
            7     932142747     991271755      18       7     7     7
            8    1988843719     422705333      18      10     4    10
            9     516966271    1437043694      18       5     8     5
           10    2137808851    1264538018      18      10     8    10

Changing Seed_2 for the CALL RANTBL statement, when I=5, forces the stream of variates for X2 to deviate from the stream of variates for X1. Changing Seed_3 on the RANTBL function, however, has no effect.

See Also

Function:

RANTBL


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.