```Date: Fri, 16 Jun 2000 09:35:31 -0700 Reply-To: Bill_Knowlton@BAXTER.COM Sender: "SAS(r) Discussion" From: Bill Knowlton Subject: Re: random number? Comments: To: barrere bendia Content-type: text/plain; charset=us-ascii Here's some info from the SAS v8 CD Manual on the 1. RANGAM function and 2. RANGAM call routine. 'Hope this helps. -Bill 1. RANGAM Syntax RANGAM(seed,a) Arguments seed is an integer. For more information on seeds, see Seed Values. Range: seed < 2(superscript: 31)-1 Note: If seed = 0, the time of day is used to initialize the seed stream. a is a numeric shape parameter. Range: a > 0. Details The RANGAM function returns a variate that is generated from a gamma distribution with parameter a. For a > 1, an acceptance-rejection method due to Cheng (1977) (See References) is used. For a = 1, an acceptance-rejection method due to Fishman is used (1978, Algorithm G2) (See References). A gamma variate X with shape parameter ALPHA and scale BETA can be generated: x=beta*rangam(seed,alpha); If 2*ALPHA is an integer, a chi-square variate X with 2*ALPHA degrees of freedom can be generated: x=2*rangam(seed,alpha); If N is a positive integer, an Erlang variate X can be generated: x=beta*rangam(seed,N); It has the distribution of the sum of N independent exponential variates whose means are BETA. And finally, a beta variate X with parameters ALPHA and BETA can be generated: y1=rangam(seed,alpha); y2=rangam(seed,beta); x=y1/(y1+y2); The CALL RANGAM routine, an alternative to the RANGAM function, gives greater control of the seed and random number streams. 2. CALL RANGAM Returns a random variate from a gamma distribution Category: Random Number Syntax CALL RANGAM(seed,a,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 RANGAM is executed. Range: seed < 2(superscript: 31) - 1 Note: If seed =0, the time of day is used to initialize the seed stream. a is a numeric shape parameter. Range: a > 0 x is a numeric variable. A new value for the random variate x is returned each time CALL RANGAM is executed. Details 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 (Cheng 1977) (See References) is used. For a =1, an acceptance-rejection method due to (Fishman 1978) (See References) is used. Comparisons The CALL RANGAM routine gives greater control of the seed and random number streams than does the RANGAM function. Examples This example uses the CALL RANGAM routine: options nodate pageno=1 linesize=80 pagesize=60; data case; retain Seed_1 Seed_2 Seed_3 45; a=2; do i=1 to 10; call rangam(Seed_1,a,X1); call rangam(Seed_2,a,X2); X3=rangam(Seed_3,a); if i=5 then do; Seed_2=18; Seed_3=18; end; output; end; run; proc print; id i; var Seed_1-Seed_3 X1-X3; run; barrere bendia cc: Sent by: "SAS(r) Subject: random number? Discussion" 06/15/00 01:40 PM Please respond to barrere bendia Hi I wante to generate number according gamma distribution with mean=mu and variance= var. I tried the functin: RANGAM(seed,a) but what mens the parameter a. The GAMMA distribution has two parameters. Can I do like this: do i=1 to 100; gama= mu + sqrt(var)*RANGA(seed,mu); output; end; drop i; ? Thank you all. _______________________________________________________________________ Why pay when you don't have to? Get AltaVista Free Internet Access now! http://jump.altavista.com/freeaccess4.go _______________________________________________________________________ ```

Back to: Top of message | Previous page | Main SAS-L page