<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create Unique SAS data sets from matrices inside a SAS/IML DO loop in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-Unique-SAS-data-sets-from-matrices-inside-a-SAS-IML-DO/m-p/439895#M4033</link>
    <description>&lt;P&gt;Hi Professor Wicklin,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much for answering my questions and anticipating my next steps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your response was very helpful and I am excited to apply your suggestions to the project I'm working on.&lt;/P&gt;</description>
    <pubDate>Sat, 24 Feb 2018 00:46:12 GMT</pubDate>
    <dc:creator>Varrelle</dc:creator>
    <dc:date>2018-02-24T00:46:12Z</dc:date>
    <item>
      <title>Create Unique SAS data sets from matrices inside a SAS/IML DO loop</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-Unique-SAS-data-sets-from-matrices-inside-a-SAS-IML-DO/m-p/439693#M4031</link>
      <description>&lt;P&gt;I am trying to store unique matrices generated inside a PROC IML DO loop into corresponding unique SAS data sets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I provide code below that is comprised by two parts.&amp;nbsp; Each part is followed by the corresponding comments ('*part 1;','*part 2;').&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Part one generates a unique matrix with each iteration of the DO loop.&amp;nbsp; The matrix is called v and is dynamically labelled with each do loop.&amp;nbsp; So at the end of the two iterations, there will be two distinct matrices, one labelled "b1", the other "b2".&lt;/P&gt;&lt;P&gt;Part 1 works fine.&amp;nbsp; Part 2 is where I am having difficulty.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Part 2, I want to store these two matrices labelled "b1" and "b2" into unique SAS data sets with distinct names.&amp;nbsp; 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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For those who might be interested, links to Professor Wicklin's blog posts that I reference follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2011/04/18/writing-data-from-a-matrix-to-a-sas-data-set.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2011/04/18/writing-data-from-a-matrix-to-a-sas-data-set.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2013/07/29/read-data-sets-array-names.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2013/07/29/read-data-sets-array-names.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here are my questions given what I've stated above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. How can I modify my Part 1 code so that I can have unique matrix names instead of unique matrix labels.&amp;nbsp; In other words, how can I have PROC IML create a matrix b1 and b2 instead of a matrix v&amp;nbsp; labelled "b1" and "b2" for iteration 1 and 2, respectively.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; 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..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope some one can help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;BR /&gt;&lt;BR /&gt;*part 1;&lt;BR /&gt;&lt;BR /&gt;do a = 1 to 2;&lt;BR /&gt;names = "b" +strip(char(a,1));&lt;BR /&gt;b = j(3,3);&lt;BR /&gt;call randseed(1234);&lt;BR /&gt;call randgen(b,"Normal");&lt;BR /&gt;v = b;&lt;BR /&gt;call valset(names,v);&lt;BR /&gt;print v[l=names];&lt;BR /&gt;&lt;BR /&gt;*part 2;&lt;BR /&gt;&lt;BR /&gt;dsNames = {names};&lt;BR /&gt;create (dsNames[1]) from v;&lt;BR /&gt;append from v;&lt;BR /&gt;close (dsNames[1]);&lt;BR /&gt;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 13:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-Unique-SAS-data-sets-from-matrices-inside-a-SAS-IML-DO/m-p/439693#M4031</guid>
      <dc:creator>Varrelle</dc:creator>
      <dc:date>2018-02-23T13:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create Unique SAS data sets from matrices inside a SAS/IML DO loop</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-Unique-SAS-data-sets-from-matrices-inside-a-SAS-IML-DO/m-p/439796#M4032</link>
      <description>&lt;P&gt;First, congratulations on being almost there. Your program just needs a small modification.&lt;/P&gt;
&lt;P&gt;Here is the modification of your program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
b = j(3,3); &lt;BR /&gt;call randseed(1234); &lt;BR /&gt;do a = 1 to 2;
*part 1; &lt;BR /&gt;   call randgen(b,"Normal");

*part 2;
   names = "b" +strip(char(a,1)); &lt;BR /&gt;   create (names) from b;
   append from b;
   close (names);
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice that the (names) variable can be used directly on the CREATE statement. Also, there is no need to use VALSET&amp;nbsp;to create a named matrix. You can reuse the&amp;nbsp;matrix name (b) within each loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You didn't say what you&amp;nbsp;are trying to accomplish, but&amp;nbsp;often the next step is to analyze each of these data sets by using a SAS procedure (maybe PROC MEANS, CORR, or PRINCOMP.)&amp;nbsp; When you write multiple data sets with different names, it is hard to analyze them all. Most people&amp;nbsp;will write a macro loop that iterates over the names of the data sets and calls a SAS procedure on each data set name.&amp;nbsp; This is inefficient, as shown in the article &lt;A href="https://blogs.sas.com/content/iml/2012/07/18/simulation-in-sas-the-slow-way-or-the-by-way.html" target="_self"&gt;"Simulation in SAS: The slow way or the BY way."&lt;/A&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are heading in that direction, consider writing all&amp;nbsp;samples into one data set and using an ID variable to indicate which observations correspond with&amp;nbsp;each sample, as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
call randseed(1234);
varNames = "ID" || ("b1":"b3");
b = j(3,3);
ID = j(3,1,1);
M = ID || b; 
create Samples from M[colname=varNames];
*part 1;
do a = 1 to 2;
   call randgen(b,"Normal");
*part 2;
   M[,1] = a;   /* assign first column */
   M[,2:4] = b; /* assign columns 2,3,4 */
   append from M;
end;
close;
quit;

proc means data=Samples;
by ID;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 19:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-Unique-SAS-data-sets-from-matrices-inside-a-SAS-IML-DO/m-p/439796#M4032</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-02-23T19:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create Unique SAS data sets from matrices inside a SAS/IML DO loop</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-Unique-SAS-data-sets-from-matrices-inside-a-SAS-IML-DO/m-p/439895#M4033</link>
      <description>&lt;P&gt;Hi Professor Wicklin,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much for answering my questions and anticipating my next steps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your response was very helpful and I am excited to apply your suggestions to the project I'm working on.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2018 00:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Create-Unique-SAS-data-sets-from-matrices-inside-a-SAS-IML-DO/m-p/439895#M4033</guid>
      <dc:creator>Varrelle</dc:creator>
      <dc:date>2018-02-24T00:46:12Z</dc:date>
    </item>
  </channel>
</rss>

