I am trying to store unique matrices generated inside a PROC IML DO loop into corresponding unique SAS data sets.
I provide code below that is comprised by two parts. Each part is followed by the corresponding comments ('*part 1;','*part 2;').
Part one generates a unique matrix with each iteration of the DO loop. The matrix is called v and is dynamically labelled with each do loop. So at the end of the two iterations, there will be two distinct matrices, one labelled "b1", the other "b2".
Part 1 works fine. Part 2 is where I am having difficulty.
In Part 2, I want to store these two matrices labelled "b1" and "b2" into unique SAS data sets with distinct names. That is, I would like to store matrix labelled "b1" into a SAS data set named work.b1 and matrix labelled "b2" into a SAS dataset named work.b2.
I've read Professor Wicklin's blogs which have gotten me close, but there appears to be an issue with my syntax in my CREATE and CLOSE statements in Part 2 of my code.
For those who might be interested, links to Professor Wicklin's blog posts that I reference follow:
https://blogs.sas.com/content/iml/2011/04/18/writing-data-from-a-matrix-to-a-sas-data-set.html
https://blogs.sas.com/content/iml/2013/07/29/read-data-sets-array-names.html
So here are my questions given what I've stated above:
1. How can I modify my Part 1 code so that I can have unique matrix names instead of unique matrix labels. In other words, how can I have PROC IML create a matrix b1 and b2 instead of a matrix v labelled "b1" and "b2" for iteration 1 and 2, respectively.
2. How can I modify my Part 2 code so that I can store the unique matrices created in Part 1 as unique SAS data sets. Meaning, how can I store the matrix generated in each iteration into SAS data sets that each SAS data set has its own name -- so that they don't overwrite each other in the work library..
Hope some one can help me.
Thanks.
proc iml;
*part 1;
do a = 1 to 2;
names = "b" +strip(char(a,1));
b = j(3,3);
call randseed(1234);
call randgen(b,"Normal");
v = b;
call valset(names,v);
print v[l=names];
*part 2;
dsNames = {names};
create (dsNames[1]) from v;
append from v;
close (dsNames[1]);
end;
quit;