Date: Tue, 20 Dec 2011 08:08:34 -0500
Reply-To: Rick Wicklin <Rick.Wicklin@SAS.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Rick Wicklin <Rick.Wicklin@SAS.COM>
Subject: Re: adding matrices in a proc iml do loop
IML is different from the DATA step in that you can generate MANY random
values with a single call. If I understand your post, you want to generate
100 random values from the MV normal distrib in 4 dimensions. To do this,
allocate a 100 x 4 matrix and send it to RANDNORMAL:
%let numreps=100;
proc iml;
call randseed(0);
/* define mux and sigmax here */
X = RANDNORMAL(&numreps,mux,sigmax);
The matrix X contains all the data. Each row is a random observation. To
get statistics (such as the sum of the vectors), use subscript reduction
operators or functions:
sumX = X[+,]; /* sum of each column */
meanX = X[:,]; /* sample mean */
stdX = sqrt(var(X)); /* std dev of each col (IML 9.22) */
covX = cov(X); /* sample covariance (should be close to sigmax) */
Here are some references:
Sampling from MV Normal: http://bit.ly/sflpLE
Subscript reduction operators: http://bit.ly/tyRduX
Notice that you do not need any loops, nor do you need any macros.
Rick Wicklin
Discuss SAS/IML issues at http://communities.sas.com/
Statistical programming and SAS/IML blog:
http://blogs.sas.com/content/iml