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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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