BookmarkSubscribeRSS Feed
GalacticAbacus
Obsidian | Level 7

Hello,

 

I've cruised this site for multiple methods of random number generation and assignment but did not find a good fit (as far as I know).

My use case is a to assign a random number to a population of individuals. I don't care about uniform distribution of the random values.

Is there a solid way to ensure no duplication of random numbers generated without having to go through do-loop iterations?

 

I realize there is a much higher chance of random number duplication than might otherwise be expected but I'm suspecting there must be a quick/efficient/best-practice out there for this...

 

Any help would be appreciated

 

TS

2 REPLIES 2
ballardw
Super User

It may be appropriate to discuss how you will use that random number. If the purpose is to select a random sample then the procedure Surveyselect may be a better idea.

 

The likelihood of duplication arises with larger numbers of records. So how big is your data set? Also sometimes "duplication" is the result of a default display format rounding values to a number of digits.

Astounding
PROC Star

This may not fit your idea of "quick" or "efficient" but it is tried and true and relatively easy to understand.  Old style coding:

 

data almost_there;

set have;

random_order = ranuni(12345);

run;

 

proc sort data=almost_there;

by random_order;

run;

 

data want;

set almost_there;

random_number = _n_;

drop random_order;

run;

 

Assign a random fraction to each observation.  Then just number the observations in order.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1003 views
  • 3 likes
  • 3 in conversation