<?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 Saving vectors into a matrix in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Saving-vectors-into-a-matrix/m-p/224710#M2273</link>
    <description>&lt;P&gt;I have a set of vectors that i generate by randomly sampling from a larger vector (the item are words/characters).&lt;BR /&gt;I do it in a do loop and after each iteration&amp;nbsp;i have a&amp;nbsp;1*4 or a 1*3 vector. I would like to collect all of these vectors into a matrix whose size is N*4, where N is the number of loops. In cases where the vectors are 1*3, the last item in a row of a matrix will be missing. I was hoping to initially create a N*4 matrix of zeros, and after each loop, insert the vector (either the 1*3 or 1*4) in row i, where i go from 1 to N.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest an efficient code for implementing this task?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help,&lt;/P&gt;&lt;P&gt;Tzachi&lt;/P&gt;</description>
    <pubDate>Wed, 09 Sep 2015 11:55:43 GMT</pubDate>
    <dc:creator>Tzachi</dc:creator>
    <dc:date>2015-09-09T11:55:43Z</dc:date>
    <item>
      <title>Saving vectors into a matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Saving-vectors-into-a-matrix/m-p/224710#M2273</link>
      <description>&lt;P&gt;I have a set of vectors that i generate by randomly sampling from a larger vector (the item are words/characters).&lt;BR /&gt;I do it in a do loop and after each iteration&amp;nbsp;i have a&amp;nbsp;1*4 or a 1*3 vector. I would like to collect all of these vectors into a matrix whose size is N*4, where N is the number of loops. In cases where the vectors are 1*3, the last item in a row of a matrix will be missing. I was hoping to initially create a N*4 matrix of zeros, and after each loop, insert the vector (either the 1*3 or 1*4) in row i, where i go from 1 to N.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone suggest an efficient code for implementing this task?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help,&lt;/P&gt;&lt;P&gt;Tzachi&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 11:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Saving-vectors-into-a-matrix/m-p/224710#M2273</guid>
      <dc:creator>Tzachi</dc:creator>
      <dc:date>2015-09-09T11:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Saving vectors into a matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Saving-vectors-into-a-matrix/m-p/224724#M2274</link>
      <description>&lt;P&gt;It would have been useful for you to have posted your code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because you are storing character values, you can't allocate a numerical matrix of zeros.&amp;nbsp; Instead you need to allocate a character matrix of blank strings.&amp;nbsp;&amp;nbsp;See the article &lt;A href="http://blogs.sas.com/content/iml/2014/05/12/how-to-create-a-string-of-a-specified-length-in-sasiml.html" target="_self"&gt;"How to create a string of a specified length"&lt;/A&gt; for tips about how to create a matrix that contains a&amp;nbsp;matrix that contains all blank strings. Then inside the loop you look at the number of elements of each sample and assign it to columns 1:3 or 1:4 of the i_th row, as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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);
list = {peter piper picked a peck of pickled peppers};
N = 10;

/* determine number of items */
numItems = sample({3 4}, N);
print numItems;

/* Allocate matrix for results. See 
   http://blogs.sas.com/content/iml/2014/05/12/how-to-create-a-string-of-a-specified-length-in-sasiml.html */
results = j(N, 4, BlankStr(nleng(list)));
do i = 1 to N;
   items = sample(list, numItems[i]);
   results[i, 1:ncol(items)] = items;
end;
print results;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 12:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Saving-vectors-into-a-matrix/m-p/224724#M2274</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2015-09-09T12:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Saving vectors into a matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Saving-vectors-into-a-matrix/m-p/225040#M2284</link>
      <description>&lt;P&gt;Thanks very much Rick!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2015 21:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Saving-vectors-into-a-matrix/m-p/225040#M2284</guid>
      <dc:creator>Tzachi</dc:creator>
      <dc:date>2015-09-10T21:32:30Z</dc:date>
    </item>
  </channel>
</rss>

