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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 817 views
  • 0 likes
  • 2 in conversation