BookmarkSubscribeRSS Feed
Fluorite | Level 6

I am trying to create several data sets say N=100 samples each of size n=20 of correlated data variables using proc IML with your suggestion and it does not work for me could you or any one help. Check  code below:


proc iml;
/** specify the mean and covariance of the population **/
Mean = {0, 0};
Cov = {1 -0.35,

           -0.35 1};

N = 20; /* size of data */
do mm=1 to 100;
dsname="user.randEff" + strip(char(mm));
call randseed(44444);  
X = RandNormal(N, Mean, Cov);
create dsname FROM X;
append from X;
close dsname;;




I expect 100 data sets with names  tagged as : user.randEff1, user.randEff2, ..., user.randEff100,

But it creates one data set user.dsname, it loops through the code alright but it looks like data is replaced after 

every loop and thus only one dataset is created.

user is the libref 


See the article, "Read data sets that are specified by an array of names," which shows how to 

Insert parentheses to get IMl to read the contents of the character variable:


create (dsname) FROM X;


However, you almost surely DO NOT want to do what you are proposing. Instead, create one data set and use an indicator variable (called SampleID) to indicate which sample is being written. You can then use BY-group processing to analyze the data. For an overview of the BY-group technique, see "Simulation in SAS: The slow way or the BY way." 

You can study the simulation code in "How to generate multiple samples from the multivariate normal distribution in SAS".

You can also use the "Write to a SAS data set from inside a SAS/IML loop."



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 2 in conversation