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

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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