Date: Fri, 23 Feb 2007 17:31:32 +1000
ReplyTo: OR Stats <stats112@GMAIL.COM>
Sender: "SAS(r) Discussion" <SASL@LISTSERV.UGA.EDU>
From: OR Stats <stats112@GMAIL.COM>
Subject: Re: Two Do Loops in One Data Step
InReplyTo: <FD746D3C07FB0C478AB951C18CE266A4A9291E@aaunsw412.au.cbainet.com>
ContentType: text/plain; charset=ISO88591; format=flowed
Hello David, David, and Ed:
Thank you for your responses. What I would like to do is generate m copies
of a n size sample of a distn that I specify. Of course, the distn is
nonstd. I would like these copies to be next to each other, and in the
same dimension in one table so that I can manipulate the copies easily for
when I'm computing the asymptotic properties of a sampling statistic of the
distn. For easy computations after generating these copies, I would like
the working matrix/design matrix to look like the following:
y(copy,observation)
y1,1 y2,1 ... ym,1
y1,2 y2,2 ... ym,2
.
.
.
y1,n y2,n ... ym,n
However, in using
%macro sample(copies,length);
%let Seed=1234;
Data sample&length.t&df(drop=LOOP);
Array SCPY{ &Copies.} S_COPY1  S_COPY&Copies.;
Do COPYCOUNT = 1 To &Copies. By 1;
Do LOOP = 1 To &Length.;
SCPY{ COPYCOUNT} = myfunction(ranuni(1234));
Output;
End;
End;
RUN;
%mend sample;
%sample(m,n);
run;
The columns although are equal in terms of the number of rows; there are
sections of missing data such that the dimensions of the entire table is no
longer nxm. Anything else in the arsenal? :)
On 2/20/07, Johnson, David <David.Johnson@cba.com.au> wrote:
>
> The %Let statement is a global one, not a data step one and you will
> have problems resolving the current "I" value within the data step in
> the way you coded it.
>
> I would approach the problem in this fashion.
>
> Two nested loops, and an array to define the columns you wish to create.
> Then referencing the columns becomes an exercise in array referencing
> rather than macro resolution.
>
> %Let Copies = 5;
>
> %Let Length = 15;
>
> %Let Seed = 1234;
>
> Data SAMPLE;
> Array SCPY{ &Copies.} S_COPY1  S_COPY&Copies.;
> Do COPYCOUNT = 1 To &Copies.;
> Do LOOP = 1 To &Length. By 1;
> P = RanUni( &Seed.);
> *transform random number p to something else;
> SCPY{ COPYCOUNT} = P; *F( P);
> %*let seed=%eval(&seed+&i);
> Output;
> End;
> End;
> Run;
>
>
> I'm not sure why you are changing your seed, but if you really want to
> do that then use Call Symput() to store the new seed value and Symget()
> to retrieve this value into the RanUni function.
>
> Naturally, the F() function won't work for me, but you can plug your own
> function into that assignment.
>
> You may want to drop the redundant LOOP and COPYCOUNT variables once you
> have finished testing.
>
> Kind regards
>
> David
>
> /*                     
> It is a capital mistake to theorize before one has data.
> Insensibly one begins to twist facts to suit theories, instead of
> theories to suit facts.
> Sir Arthur Conan Doyle
>                      */
>
> Original Message
> From: SAS(r) Discussion [mailto:SASL@LISTSERV.UGA.EDU] On Behalf Of OR
> Stats
> Sent: Tuesday, 20 February 2007 12:46 PM
> To: SASL@LISTSERV.UGA.EDU
> Subject: Two Do Loops in One Data Step
>
> Hello All:
>
> I would like to create two Do loops in one datastep. But I'm not sure
> if there is not a faster way of coding this up. Basically, I would like
> to randomly generate n x m random numbers, where 'm' is my replicate
> sets of size n. Generating these numbers, it wouldn't matter whether i
> generated n*m times, m sets of random numbers of n length.
>
> So the programming in the Data Step is just a matter of formatting the
> output. After generating these numbers, I would need to treat each
> vector of nlength miterations. This is what I have so far:
> data sample;
> %let i=1;
> do while (&i<=&copies);
> do _n_=1 to &length;
> p=ranuni(&seed);
> *transform random number p to something else;
> s_copy&i=f(p);
> %let seed=%eval(&seed+&i);
> output;
> end;
> %let i=&i+1;
> end;
> run;quit;
>
> So from the above, I would have a table that is of length '&length' and
> &copies across, where each column/variable is named dynamically
> 's_copy&i'
> ThankU
>
> ************** IMPORTANT MESSAGE *****************************
> This email message is intended only for the addressee(s) and contains
> information which may be
> confidential.
> If you are not the intended recipient please advise the sender by return
> email, do not use or
> disclose the contents, and delete the message and any attachments from
> your system. Unless
> specifically indicated, this email does not constitute formal advice or
> commitment by the sender
> or the Commonwealth Bank of Australia (ABN 48 123 123 124) or its
> subsidiaries.
> We can be contacted through our web site: commbank.com.au.
> If you no longer wish to receive commercial electronic messages from us,
> please reply to this
> email by typing Unsubscribe in the subject line.
> **************************************************************
>
