Date: Fri, 15 Jan 2010 10:24:18 -0600
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: assign a unique random integer to each unique id
In-Reply-To: <286809.81871.qm@web30408.mail.mud.yahoo.com>
Content-Type: text/plain; charset=ISO-8859-1
I believe that will generally work, but the size of your sample determines
if it's likely to work 100%. You won't get 100% guarantee that it will be
unique, because the period of the ranuni function is much larger than that;
so periodically if reduced to a period of only 1e7 it will duplicate. 1e7
should be enough in my experience for a 1e4 order sample size.
A safer way would be to generate a random number (not an integer, just the
ranuni() itself), then sort by it, then use _N_ . That ensures a unique
integer.
-Joe
On Fri, Jan 15, 2010 at 10:09 AM, Ai Hua Wang <aihuawang@yahoo.com> wrote:
> Hi,
>
> I was wondering if anybody in this list could advise how I can assign a
> unique random integer to each unique id. I have written the following code
> but it does not allow me to get the unique random intergers. The 10000000 is
> proportional to the size of the data set. Do I miss anything in the codes?
> Please kindly provide your suggestions.
>
> Thanks,
> Aihua
>
>
> data temp;
> set datset1;
> urand=ceil(ranuni(1)*10000000);
> run;
>
>
>
> __________________________________________________________________
> Be smarter than spam. See how smart SpamGuard is at giving junk email the
> boot with the All-new Yahoo! Mail. Click on Options in Mail and switch to
> New Mail today or register for free at http://mail.yahoo.ca
>
|