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