BookmarkSubscribeRSS Feed
wV17
Calcite | Level 5

Hi, I have been studying RANUNI function and I don't understand why sometimes people uses it with this expression: int(RANUNI(36830)*n) . 

What does the number inside of the function mean and why is it sometimes multiplied with "n"?

Thanks

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

The number is called the random number seed. The seed value controls the sequence of random numbers. See this article

 

http://blogs.sas.com/content/iml/2011/08/31/random-number-streams-in-sas-how-do-they-work.html

Rick_SAS
SAS Super FREQ

But you should be aware that the RAND function is the preferred way to generate random numbers. See "Six reasons you should stop using the RANUNI function to generate random numbers" Item #3 addresses your question.

art297
Opal | Level 21

I see that you've already got half your answer .. so here is the other half. The *n is there to get a number between 1 and n.

A more general way to specify it is: x=min + floor((1 + max - min) * rand("uniform"))

 

That way you can select a random number between min and max.

 

Also, if you use a seed of zero, SAS will use time of day to select which "table" to use.

 

Art, CEO, AnalystFinder.com

 

Rick_SAS
SAS Super FREQ

It looks like you are trying to generate a random integer in the range [a,b].

See the article "How to generate random integers in SAS"

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 1035 views
  • 3 likes
  • 5 in conversation