Date: Tue, 31 Aug 2004 16:17:17 -0400
Reply-To: "Huang, Ya" <yhuang@AMYLIN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Huang, Ya" <yhuang@AMYLIN.COM>
Subject: Re: Randomly choose a variable value
On Tue, 31 Aug 2004 12:41:12 -0700, Dan Litsky <d_litsky@YAHOO.COM> wrote:
>Is there a way to search through 6 (or so) variables in a record and
randomly choose one of the values?
>
>Thanks,
>Dan
>
>
>---------------------------------
>Do you Yahoo!?
>Yahoo! Mail - 50x more storage than other providers!
Use array and ranuni() generated number as the index:
data xx;
array vv(6) v1-v6 (1,2,3,4,5,6);
do i=1 to 5;
output;
end;
run;
data xx;
set xx;
array vv(6) v1-v6;
randpick=vv(ceil(ranuni(123)*6));
drop i;
run;
proc print noobs;
run;
---------
v1 v2 v3 v4 v5 v6 randpick
1 2 3 4 5 6 5
1 2 3 4 5 6 2
1 2 3 4 5 6 2
1 2 3 4 5 6 6
1 2 3 4 5 6 3
Kind regards,
Ya Huang
|