|
This will work as advertised, but try inserting the statement
retrycount = 0;
at the beginning of the outer loop and the statement
retrycount + 1;
at the end of the inner loop (the middle DO structure), then inspect the
results.
On the last iteration, the program will have to try many times before it
randomly generates the one and only unused value.
On Thu, 15 May 2003 16:56:40 -0400, Droogendyk, Harry
<Harry.Droogendyk@CIBC.COM> wrote:
>Sorry, missed the "unique". Keep track of the used values in an array:
>
>data a;
> array r(10000) $1 _temporary_;
> do j = 1 to 10000;
> do until(0);
> rand = ceil(ranuni(0)*10000);
> if missing(r(rand)) then do;
> r(rand) = '1';
> output;
> leave;
> end;
> end;
> end;
>run;
>
>proc sql;
> select count(distinct rand) from a;
>quit;
>
>
>
>
>
>
>-----Original Message-----
>From: Tim Corn [mailto:tim19972003@yahoo.com]
>Sent: Thursday, May 15, 2003 4:49 PM
>To: Droogendyk, Harry
>Cc: SAS-L@LISTSERV.UGA.EDU
>Subject: RE: Generate Random Number???
>
>
>Harry,
>
>I tried your suggestion. But this will lead to the duplicate random number.
>Thanks again for your advice!
>
>Tim
>
>"Droogendyk, Harry" <Harry.Droogendyk@CIBC.com> wrote:
>
>random = ceil(ranuni(seed_value) * 10000);
>
>-----Original Message-----
>From: Tim Corn [mailto:tim19972003@YAHOO.COM]
>Sent: Thursday, May 15, 2003 4:26 PM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Generate Random Number???
>
>Hello,
>
>I want to generate an unique random number for each
>observation of a sas dataset. And the range of the random number should be
>1~10,000. How can I do this? I tried using ranuni function, but the numbers
>are less than 1. Any suggetion? Thank in advance for your valuable advice!
>
>Tim
>
>
>---------------------------------
>Do you Yahoo!?
>The New Yahoo! Search - Faster. Easier. Bingo.
>
>
>
> _____
>
>Do you Yahoo!?
>The New <http://us.rd.yahoo.com/search/mailsig/*http://search.yahoo.com>
>Yahoo! Search - Faster. Easier. Bingo.
|