<?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: Creating and accessing an IML List of Lists in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767694#M5645</link>
    <description>&lt;P&gt;Please show what you have tried.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep in mind that MATLAB data structures are more general than lists. The main purpose of the SAS/IML lists is to pack objects of various types into a single object that can be passed to and from modules. You might be able to coerce lists to emulate other data structures, but you will have to be clever.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Sep 2021 13:25:14 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2021-09-14T13:25:14Z</dc:date>
    <item>
      <title>Creating and accessing an IML List of Lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767550#M5642</link>
      <description>&lt;P&gt;MATLAB has structure syntax like&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;a.b( index ).c = d ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;where index is an integer.&lt;/P&gt;&lt;P&gt;How do I create an IML list equivalent to the MATLAB statement? This will be a hierarchical heterogeneous list, I think.&lt;/P&gt;&lt;P&gt;Given the first instance, e.g.,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;a.b(1).c = d ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;if index is incremented, how do I tell IML to create the second instance,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;a.b(2).c = e;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;so that an array of sublists is created?&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 20:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767550#M5642</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-09-13T20:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Creating and accessing an IML List of Lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767638#M5643</link>
      <description>&lt;P&gt;Please post a SAS/IML program that shows what you are trying to accomplish. Use the IML syntax, not the syntax from a different language.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a general rule, use &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_013/imlug/imlug_langref_sect236.htm" target="_self"&gt;ListAddItem&lt;/A&gt;&amp;nbsp;to add a new item to an existing list. If the item you add is a list, you can use ListAddItem to add items to that list, thus emulating a hierarchical structure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 09:40:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767638#M5643</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-09-14T09:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating and accessing an IML List of Lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767688#M5644</link>
      <description>&lt;P&gt;Hi Rick,&lt;/P&gt;
&lt;P&gt;Can you give an example of how you can use ListAddItem to extend a sublist?&amp;nbsp; I can make it work at the top level, but not lower down in the hierarchy.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 13:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767688#M5644</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2021-09-14T13:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating and accessing an IML List of Lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767694#M5645</link>
      <description>&lt;P&gt;Please show what you have tried.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep in mind that MATLAB data structures are more general than lists. The main purpose of the SAS/IML lists is to pack objects of various types into a single object that can be passed to and from modules. You might be able to coerce lists to emulate other data structures, but you will have to be clever.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 13:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767694#M5645</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-09-14T13:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating and accessing an IML List of Lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767739#M5646</link>
      <description>&lt;P&gt;Not sure what people are asking, but maybe study this program and see if it helps to answer your questions. At least it provides a concrete example that we can discuss.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
package load ListUtil;

/* create list of lists. 
   Specify L$1$1, L$1$2, L$2$1, and L$2$2 */
L = ListCreate(3);
L$1 = ListCreate(2);
L$1$1 = 'L11';
L$1$2 = 12;
L$2 = ListCreate(2);
L$2$1 = 'L21';
L$2$2 = 22;

/* Now add a third item to L$2 and access it as L$2$3 */
newVal = 23;
L2 = ListGetSubItem(L, 2, 'm');     /* get the sublist you want to expand */
call ListAddItem(L2, newVal);       /* expand it */
call ListSetSubItem(L, 2, L2, 'm'); /* set it back into the list */
call struct(L);

check = L$2$3;     /* make sure the new item exists */
print check;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Sep 2021 14:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767739#M5646</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-09-14T14:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: Creating and accessing an IML List of Lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767740#M5647</link>
      <description>&lt;P&gt;Here is an example.&amp;nbsp; If I create a list with 3 items where the second item is itself a list - like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;L = [[1:3], [i(2),i(3)], [4:6]];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then I might want to add i(4) to the sublist.&amp;nbsp;&amp;nbsp; I have tried syntax like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Call ListAddItem(L$2, i(4));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but this, and using L[2] instead of L$2, both leave L unmodified. If by being clever you mean something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  L$2 = [ L$2 || [i(4)] ];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then this works but essentially I have just manually reconstructed L$2.&amp;nbsp; It feels like there should be a subroutine called ListAddSubItem to do what I want, but it is not there.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 14:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767740#M5647</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2021-09-14T14:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating and accessing an IML List of Lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767764#M5648</link>
      <description>&lt;P&gt;Thank you Rick, I see how to do it now.&amp;nbsp; So following your example I could make my own version of ListAddSubItem as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;

start ListAddSubItem(A, Pos, Val);
  if type(A) ^= 'L' then return;
  B = ListGetSubItem(A, Pos, 'm');
  if type(B) = 'L' then call ListAddItem(B, Val);
  call ListSetSubItem(A, Pos, B, 'm');
finish;

package load listutil;

L = [ 2, [5, 6], 9 ];
call ListAddSubItem(L, 2, 7);
call struct(L);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Sep 2021 15:49:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767764#M5648</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2021-09-14T15:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating and accessing an IML List of Lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767765#M5649</link>
      <description>&lt;P&gt;I thank all of you for your interest in my question and for your suggestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a SAS/IML list with the following structure:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;a$1$c = 'item 1'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;a$2$c = 'item 2'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;a$3$c = 'item 3'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;b$1$c = 'item 1'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;b$2$c = 'item 2'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;b$3$c = 'item 3'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;b$4$c = 'item 4'&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;...&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;After studying Dr. Wicklin's example, I think that this code does the task:&lt;/P&gt;&lt;P&gt;-----------&lt;/P&gt;&lt;PRE&gt;proc iml ; package load listutil ;&lt;BR /&gt;L = [] ;&lt;BR /&gt;do i = 1 to 2 ;&lt;BR /&gt;   call ListAddItem( L, [ #type='input', i, #item='item' + char(i) ] ) ;&lt;BR /&gt;end ;&lt;BR /&gt;do i = 1 to 3 ;&lt;BR /&gt;   call ListAddItem( L, [ #type='output', i, #item='item' + char(i) ] ) ;&lt;BR /&gt;end ;  &lt;BR /&gt;call struct( L ) ;&lt;BR /&gt;quit ;&lt;/PRE&gt;&lt;P&gt;----------&lt;/P&gt;&lt;P&gt;How can I produce the same result using the list syntax "$" instead of "ListAddItem" ?&lt;/P&gt;&lt;P&gt;Ross&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 15:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767765#M5649</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-09-14T15:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Creating and accessing an IML List of Lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767773#M5650</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;How can I produce the same result using the list syntax "$" instead of "ListAddItem" ?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't, unless you use concatenation as Ian showed earlier. The '$' syntax refers to an item that already exists. The ListAddItem function creates a new item in the list.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Think of the $ operator as analogous to subscripts for matrices. If you define&lt;BR /&gt;m = 11:13;&lt;/P&gt;
&lt;P&gt;you cannot reference m[4] because that element does not exist. If you want to add a new item to the m matrix, you need to use concatenation or "allocate and copy":&lt;/P&gt;
&lt;P&gt;m1 = m || {14};&lt;BR /&gt;or&lt;/P&gt;
&lt;P&gt;m2 = j(1, ncol(m)+1, .);&lt;BR /&gt;m2[1:3] = m;&lt;BR /&gt;m2[4] = 14;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 16:59:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Creating-and-accessing-an-IML-List-of-Lists/m-p/767773#M5650</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-09-14T16:59:44Z</dc:date>
    </item>
  </channel>
</rss>

