Date: Mon, 20 Sep 1999 14:19:18 +0100
Reply-To: John Whittington <medisci@POWERNET.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: John Whittington <medisci@POWERNET.COM>
Subject: Re: Random Selection: Anything More Elegant
In-Reply-To: <199909200808.JAA05984@mail-relay.power.net.uk>
Content-Type: text/plain; charset="us-ascii"
At 09:59 20/09/99 +0200, F a b r i z i o wrote:
>Hi John, your algorithm is definitely very nice, I only would
>suggest you replace the references to 'n' by references to
>'totalobs'. At least, I think that is what you need. Am I right?
>('totalobs' is currently uninitialized, and 'n' is not referenced
> at all, hence my conclusion)
Sorry, yes - I converted the 'n' in my usual code to 'totalobs', to be
consistent with the code others have posted - but missed a couple of the
occurrences of 'n.! The code should have read:
data just20 (drop = needed totalobs);
retain needed 20 totalobs;
if _n_=1 then totalobs = total;
do i = 1 to total ;
if ranuni(0) le needed/totalobs then do;
set one nobs = total point = i ;
needed = needed - 1;
output ;
end;
totalobs = totalobs - 1 ;
if needed = 0 then stop ;
end ;
run ;
Sorry for the oversight; I hope it didn't cause anyone any confusion.
Kind Regards
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: medisci@powernet.com
Buckingham MK18 4EL, UK mediscience@compuserve.com
----------------------------------------------------------------
|