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 (August 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
In-Reply-To:   <200607281950.k6SHWf6i010656@mailgw.cc.uga.edu>
Content-Type:   text/plain; format=flowed

stats112@GMAIL.COM wrote: >Hello Everyone, > >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, >fifth >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 SAS functions that are already written, instead of fighting with this yourself. CALL RANPERK() will od what you want without resorting to macros or self-constructed code.

HTH, David -- David L. Cassell mathematical statistician Design Pathways 3115 NW Norwood Pl. Corvallis OR 97330

_________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


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