LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 1998, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 2 Oct 1998 02:46:34 +0100
Reply-To:     John Whittington <medisci@POWERNET.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         John Whittington <medisci@POWERNET.COM>
Subject:      Re: random sample selection
Comments: To: MelliJ@AOL.COM
Content-Type: text/plain; charset="us-ascii"

Melanie,

At 19:06 01/10/98 EDT, Melanie Barish wrote: >Hello everyone! Can anyone give me some suggestions as to the proper code for >a random sample selection. Thus far, at the recommendation of a co-worker, I >have used a ranuni command, followed by a data step with a retain statement. >However, when attempting to select a 20% random sample, I am not getting >exactly 20%. For instance, when I select 20% of a data set that contains 36 >observations, I get 9 observations. Thanks for the help...

You'll find this question addressed frequently in the SAS-L Archives. The most common solution to get a random sample of precise specified size is along the lines of:

data sample (drop = k) ; k = 1000 ; /* specify sample size required */ if 0 then set bigdata nobs = n ; /* get nobs, without reading anything */ do i = 1 to n while (k > 0) ; if ranuni(123456) < k/n then do; k = k-1; set bigdata point = i ; output ; end ; n=n-1 ; end ; stop ; run ;

If you want to specify the exact proportion to be sampled, rather than the exact size of the sample, the start of that can be modified, something like:

data sample (drop = k) ; if 0 then set bigdata nobs = n ; /* get nobs, without reading anything */ k = n * 0.XXX ; /* 0.XXX = desired proportion */

Any help ?

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


Back to: Top of message | Previous page | Main SAS-L page