BookmarkSubscribeRSS Feed
HeidiDT
Quartz | Level 8

Hi All

I am hoping someone has come across this issue previously and knows why it happens: I am assigning a random number between 1 and 1,000 to a daily feed of data by making use of the RANUNI function:

                SAS_RANDOM_NUMBER  = int(1000*ranuni(-1));

The problem I have is that on certain days the same number is allocated to 90% of the records, so not so random after all. Has anyone ever come across this problem? 

6 REPLIES 6
Kurt_Bremser
Super User

Don't use RANUNI, use the improved RAND:

call streaminit(-1);
SAS_RANDOM_NUMBER  = int(1000*rand('uniform'));

If you want a uniform integer distribution, use

rand('integer',1000);
HeidiDT
Quartz | Level 8

Thanks guys! Will that explain why more than 90% of the records get the same number assigned though? Is RANUNI that "bad"?

Kurt_Bremser
Super User

Well, I never experienced something as egregious as what you describe, but then I rarely needed random numbers. I do mostly ETL work, no simulations.

And I've been using RAND since it was introduced.

Watts
SAS Employee

It looks like you're specifying a seed value of -1, which uses the time of day to initialize the seed stream. I don't know how you're using the RANUNI function to generate the list of random numbers, but if (?) you're including the function in a loop, it's possible that this runs faster than the clock updates -- and therefore reuses the same seed.

 

For more information, see How to Generate Random Numbers in SAS by @Rick_SAS .

 

 

Rick_SAS
SAS Super FREQ

If you post the code you are using, we can say more about what you are seeing and why.

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
  • 6 replies
  • 748 views
  • 0 likes
  • 5 in conversation