BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
data_null__
Jade | Level 19
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.
deleted_user
Not applicable
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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1387 views
  • 0 likes
  • 2 in conversation