DATA Step, Macro, Functions and more

thanks. I have a question for ranuni(seed*&i).

Reply
N/A
Posts: 0

thanks. I have a question for ranuni(seed*&i).

I test a code:
%let i=10;
data wjx;
A=2+200*ranuni(&seed1*&i);
B=Ranbin(75,1000,0.1);
C=100*ranuni(0);
D=100*ranuni(3);
run;
proc print data=wjx;run;

wjx:
A=13.6254
B=109
C= 62.0198
D=88.3135

question:
1. when I changed seed1 or changed i(like%let i=110 ), the B,C,D gave me difference number,why?
2, when I changed the B's seed or C's seed or D's seed values,the B,C,D always stayed same, why?

data wjx;
A=2+200*ranuni(&seed1*&i);
B=Ranbin(175,1000,0.1);
C=100*ranuni(10);
D=100*ranuni(23);
run;



thanks a million!
Alex
Respected Advisor
Posts: 3,799

Re: thanks. I have a question for ranuni(seed*&i).

Posted in reply to deleted_user
When you use the FUNCTION from of the random number generators SAS keeps only one SEED value in a memory location that we do not have control over.

Therefore each RANzzz call uses the value stored in the same SEED buffer, regardless of whether it is the nth call to the same function or a different function.

As stated in the documentation
[pre]
Tip: If you want to change the seed value during execution, you must use the CALL RANBIN routine instead of the RANBIN function.

and

The CALL RANBIN routine, an alternative to the RANBIN function, gives greater control of the seed and random number streams.

[/pre]

This appies to RANUNI as well.
N/A
Posts: 0

Re: thanks. I have a question for ranuni(seed*&i).

Posted in reply to data_null__
thank U very much!!!

Only the first seed encountered is used to initialize that random number stream. Any additional seeds provided are ignored.

to change streams, can use the CALL RANxxx versions of the random number generators. Message was edited by: sasJunior
Ask a Question
Discussion stats
  • 2 replies
  • 134 views
  • 0 likes
  • 2 in conversation