Date: Thu, 11 Mar 2004 06:12:40 -0800
Reply-To: Dale McLerran <stringplayer_2@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dale McLerran <stringplayer_2@YAHOO.COM>
Subject: Re: Stratified random sample using arrays
In-Reply-To: <200403110943.i2B9h0K03493@listserv.cc.uga.edu>
Content-Type: text/plain; charset=us-ascii
Ben,
Why do you need an array? Just sort by x and z. In a subsequent
data step, keep a counter of how many observations with a specific
value of x have been observed. As long as the number of
observations of stratum variable x are below the target number,
then output the observation.
/* Use a format to identify the number of */
/* observations to sample from each stratum. */
proc format;
invalue strat_n
1 = <p>
2 = <q>
3 = <r>;
run;
/* Construct random variable z. */
data mydata;
retain seed <seedvalue>;
call ranuni(seed,z);
drop seed;
run;
/* Sort z within x */
proc sort data=mydata;
by x z;
run;
/* Data step to select n{i} observations from each stratum */
data mydata;
set mydata;
by x;
if first.x then stratum_n=0;
stratum_n + 1;
if input(x, strat_n.)<=stratum_n then output;
keep x y;
run;
Best wishes,
Dale
--- ben.powell@CLA.CO.UK wrote:
> Dear SAS-L
>
> I have a dataset from which I want to make a stratified random
> sample. The
> dataset contains two variables (x,y) and are sorted by x. y is
> otherwise
> unique. I want to take p of x1, q of x2 and r of x3, etc.
>
> I know how to do this using Archer Gravely's proc rank method having
> first
> sorted by a random variable. *I DON'T HAVE PROC SURVEYSELECT*.
>
> What I would like to do is perform the same thing using arrays but
> cannnot
> work it out. The logic that I can't put into code goes:
>
> Where the dataset is presorted by a random variable z and also by x,
> load each value of x into an array and if the count is over a target
> number
> then delete; keep x and y.
>
> Any help gratefully received.
=====
---------------------------------------
Dale McLerran
Fred Hutchinson Cancer Research Center
mailto: dmclerra@fhcrc.org
Ph: (206) 667-2926
Fax: (206) 667-5977
---------------------------------------
__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com