|Date: ||Mon, 31 Jul 2006 22:01:06 -0700|
|Reply-To: ||David L Cassell <davidlcassell@MSN.COM>|
|Sender: ||"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>|
|From: ||David L Cassell <davidlcassell@MSN.COM>|
|Subject: ||Re: Removing i-th element from array|
|Content-Type: ||text/plain; format=flowed|
>Does anyone know how we may dynamically remove the first element of an
>initial array. For example:
>%let arraylstb = 5 3 2 1 10;
>I would like to remove the first element of this array, so that arraylstb
>becomes [ 3 2 1 10].
>Moreover, how do I do the same for removing the second, third, fourth,
>element of the initially array? The reason for this question is at each
>step in my loop, a random number is generated and depending on that number,
>I would set a variable equal to the corresponding element (call it 'i') in
>the array and remove this i-th element from the array and iterate again.
>Basically, I would like to randomly sample w.o. replacement.
>Thanks so much!
First off, you don't need to kill yourself with macro code here. You could
just use an ARRAY statement to load the set of constants into a data step
array, and work with the array instead. (The list of elements becomes the
list of constants that go in parens in the ARRAY statement.)
But you don't even need that. If you're doing all this work, you are going
to end up choosing k out of n items for some k, right? So you can use the
functions that are already written, instead of fighting with this yourself.
CALL RANPERK() will od what you want without resorting to macros or
David L. Cassell
3115 NW Norwood Pl.
Corvallis OR 97330
Express yourself instantly with MSN Messenger! Download today - it's FREE!