<?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 sas/iml lists in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/sas-iml-lists/m-p/747193#M5482</link>
    <description>&lt;P&gt;I am trying to extract multiple items from a SAS/IML list. I have limited success using colvec() and rowvec() but when I try to simplify my code, I run into syntax errors that I do not understand. Here is my code:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;proc iml ;&lt;BR /&gt;package load listutil ;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;e = [ #'nobs' =3&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , #'nvars'=2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , #'type' =[ 'N' ] || [ 'N' ]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , #'name' =[ 'var1' ] || [ 'var2' ]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , #'cols' =[{ 11 21 31 }] || [{ 12 22 32 }]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ] ;&lt;BR /&gt;&lt;BR /&gt;call listprint( e ) ;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;columns = colvec( e$'cols'$1 ) || colvec( e$'cols'$2 ) ; /* this is awkward but "columns = e$'cols'$1 || e$'cols'$2" gives me a list and I want a numeric matrix */&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;BR /&gt;print columns ;&lt;BR /&gt;&lt;BR /&gt;colnames = rowvec( e$'name'$1 ) || rowvec( e$'name'$2 ) ; /* same reason as for columns, above */&lt;BR /&gt;print colnames ;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;tbl = TableCreate( colnames, columns ) ; /* this code works, but getting to this point is inelegant, IMHO */&lt;BR /&gt;call TablePrint( tbl ) ;&lt;BR /&gt;&lt;BR /&gt;sublist = [ 1:2 ] ;&lt;BR /&gt;a = e$'cols'$sublist ; /* is this the correct syntax? the SAS/IML interpreter thinks otherwise */&lt;BR /&gt;call listprint ( a ) ;&lt;BR /&gt;quit ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to extract columns 1 and 2 from list item e$'cols' with one subsetting operation so I defined a sublist and tried to define list a, but failed. Where am I going wrong?&lt;/P&gt;</description>
    <pubDate>Thu, 10 Jun 2021 19:27:59 GMT</pubDate>
    <dc:creator>rbettinger</dc:creator>
    <dc:date>2021-06-10T19:27:59Z</dc:date>
    <item>
      <title>sas/iml lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/sas-iml-lists/m-p/747193#M5482</link>
      <description>&lt;P&gt;I am trying to extract multiple items from a SAS/IML list. I have limited success using colvec() and rowvec() but when I try to simplify my code, I run into syntax errors that I do not understand. Here is my code:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;proc iml ;&lt;BR /&gt;package load listutil ;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;e = [ #'nobs' =3&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , #'nvars'=2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , #'type' =[ 'N' ] || [ 'N' ]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , #'name' =[ 'var1' ] || [ 'var2' ]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , #'cols' =[{ 11 21 31 }] || [{ 12 22 32 }]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ] ;&lt;BR /&gt;&lt;BR /&gt;call listprint( e ) ;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;columns = colvec( e$'cols'$1 ) || colvec( e$'cols'$2 ) ; /* this is awkward but "columns = e$'cols'$1 || e$'cols'$2" gives me a list and I want a numeric matrix */&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;BR /&gt;print columns ;&lt;BR /&gt;&lt;BR /&gt;colnames = rowvec( e$'name'$1 ) || rowvec( e$'name'$2 ) ; /* same reason as for columns, above */&lt;BR /&gt;print colnames ;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;tbl = TableCreate( colnames, columns ) ; /* this code works, but getting to this point is inelegant, IMHO */&lt;BR /&gt;call TablePrint( tbl ) ;&lt;BR /&gt;&lt;BR /&gt;sublist = [ 1:2 ] ;&lt;BR /&gt;a = e$'cols'$sublist ; /* is this the correct syntax? the SAS/IML interpreter thinks otherwise */&lt;BR /&gt;call listprint ( a ) ;&lt;BR /&gt;quit ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to extract columns 1 and 2 from list item e$'cols' with one subsetting operation so I defined a sublist and tried to define list a, but failed. Where am I going wrong?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 19:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/sas-iml-lists/m-p/747193#M5482</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-06-10T19:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: sas/iml lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/sas-iml-lists/m-p/747321#M5483</link>
      <description>Post it at IML forum and calling &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;</description>
      <pubDate>Fri, 11 Jun 2021 12:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/sas-iml-lists/m-p/747321#M5483</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-11T12:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: sas/iml lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/sas-iml-lists/m-p/747332#M5484</link>
      <description>&lt;P&gt;Your confusion is caused because the brackets ([...]) are used both for subscript operations and to define lists. If you want to extract the 1st and 2nd items in a list, use the subscript operator:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;idx = 1:2;
a = e$'cols'[idx]; /* subscripts, not a list */
call listprint ( a ) ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With regard to your meta-question ("extracting the data is inelegant"), I suggest that you might benefit by rethinking your data structure. Here are a few concrete suggestions:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Don't make everything in 'e' a list. If a component contains homogeneous elements (such as 'type' and 'name'), make it a vector or matrix.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Store the elements of 'cols' as column vectors to eliminate having to call COLVEC every time you retrieve a column&lt;/LI&gt;
&lt;LI&gt;Use the TableAddVar function to construct a table. Your current method will fail if you have both numerical and character data.&lt;/LI&gt;
&lt;LI&gt;I prefer CALL STRUCT to CALL LISTPRINT. It provides a nice summary of the structure of the list and its items and subitems.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;The following program might give you some ideas to play with:&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 ;

/* if data are homogeneous, use a matrix instead of a list */
e = [ #'nobs' =3
      , #'nvars'=3
      , #'type' ={'N' 'N' 'N'}
      , #'name' ={'var1' 'var2' 'var3'}
      , #'cols' =[{ 11, 21, 31 }, { 12, 22, 32 }, {A, B, C}]
      ] ;

call struct( e ) ;

/* to create a table from names and columns, use TableAddVar */
varIdx = {1 3};
tbl = TableCreate();
do i = 1 to ncol(varIdx);
   k = varIdx[i];
   call TableAddVar(tbl, e$'name'[k], e$'cols'$k);
end;
call TablePrint( tbl ) ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Jun 2021 13:44:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/sas-iml-lists/m-p/747332#M5484</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-06-11T13:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: sas/iml lists</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/sas-iml-lists/m-p/747472#M5485</link>
      <description>&lt;P&gt;Thank you for calling my attention to the 'SAS/IML' forum and Rick Wicklin.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2021 19:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/sas-iml-lists/m-p/747472#M5485</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-06-11T19:30:40Z</dc:date>
    </item>
  </channel>
</rss>

