BookmarkSubscribeRSS Feed
sbampah
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;;

end;
quit;

 

 

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 

1 REPLY 1
Rick_SAS
SAS Super FREQ

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."

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 437 views
  • 0 likes
  • 2 in conversation