```Date: Thu, 30 Jul 2009 16:52:40 -0500 Reply-To: Joe Matise Sender: "SAS(r) Discussion" From: Joe Matise Subject: Re: Picking up a random number stream where you've left off--how? Comments: To: "Pardee, Roy" In-Reply-To: <587F57B26FAA8246A81D10D251EB8AB4220CAAC1@EXCH07.GHCMASTER.GHC.ORG> Content-Type: text/plain; charset=ISO-8859-1 You need to save out the random number seed. IIRC if you use CALL RANUNI the new seed value is the next seed in the stream; then you can save this (using SYMPUT, or to a dataset, or whatever). So these produce identical values for y: data test1; x = 7; do _n_ = 1 to 50; call ranuni(x,y); output; end; run; data test2; do _n_ = 1 to 50; y = ranuni(7); output; end; run; but in test1, x is the new seed value (the next one in the stream), so you could save x aside (with CALL SYMPUT, or just in a dataset) for later. For example, test3 has the 26-50 rows from test2: data test; x = 7; do _n_ = 1 to 25; call ranuni(x,y); output; end; call symput('x',x); run; data test3; x=&x; do _n_ = 1 to 25; call ranuni(x,y); output; end; run; -Joe On Thu, Jul 30, 2009 at 4:43 PM, Pardee, Roy wrote: > Hey All, > > I'm randomizing some doctors for a study in several batches, as they get > recruited. So--20 docs now, 50 next time, etc. I'd like to use a > particular seed for the random number generation, so if we ever need to > reproduce the sequence we can. > > Because I'm doing this in several batches, I'd like to pick up the stream > of random numbers where I left off at the last randomization. My first > thought was that I could catch back up to where I left off by calling > uniform() once for every doc I'd already randomized--so frx: > > data useless ; > set perm.already_randomized_docs ; > ** Burn off a random number for each already-randomized doc. ; > randy = uniform(&seed) ; > run ; > > data new_docs ; > set perm.not_yet_randomized ; > condition = round(uniform(&seed)) ; > run ; > > But some experimenting seems to reveal that the stream gets re-set between > data steps. That is uniform(&seed) will return the same number in both > steps when _n_ is 1, 2, 3, and so on. So that does not seem like an option. > > My next thought was to burn off numbers in a do loop, like so: > > data new_docs ; > set perm.not_yet_randomized ; > do i = 1 to &num_already_randomized ; > randy = uniform(&seed) ; > end ; > condition = round(uniform(&seed)) ; > run ; > > But that do loop will run once per row, won't it? So that's not a fix > either. > > Is there a good way to pick up a particular random number stream from where > you've left off? > > Many thanks! > > -Roy > > > GHC Confidentiality Statement > > This message and any attached files might contain confidential information > protected by federal and state law. The information is intended only for the > use of the individual(s) or entities originally named as addressees. The > improper disclosure of such information may be subject to civil or criminal > penalties. If this message reached you in error, please contact the sender > and destroy this message. Disclosing, copying, forwarding, or distributing > the information by unauthorized individuals or entities is strictly > prohibited by law. > ```

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