<?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: Two questions: Appending an item to a list, and using a variable in defining a list item in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Two-questions-Appending-an-item-to-a-list-and-using-a-variable/m-p/775790#M5712</link>
    <description>&lt;P&gt;I had never thought to use SAS/MACRO within SAS/IML, but the CALL SYMPUT suggestion works just fine! Thank you very much, Rick.&lt;/P&gt;
&lt;P&gt;Here is my code. The first example does not use CALL SYMPUT, and the second one does, giving me the flexibility that I need.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml ; package load listutil ;
print 'this code does not use CALL SYMPUT' ;
L = [ #'Input' = ] ;
call struct(L) ; call listprint(L) ;

L$([ 'Input' ]) =  L$([ 'Input' ]) || [ #'Var1' = [ #a=, #b=, #c=]] ;
call struct(L) ; call listprint(L) ;

L$([ 'Input', 'Var1' ]) = L$([ 'Input', 'Var1' ]) || [ #'MF1'=[ #mf1=, #mf2=, #mf3=, #mf4=]] ;
call struct(L) ; call listprint(L$'Input'$'Var1') ;
L_I_V = L$'Input'$'Var1'$'MF1' ; call struct(L_I_V ) ;

print 'this code uses CALL SYMPUT' ;
call symput( 'VAR', "Var1" ) ;
call symput( 'MF' , 'MF1'  ) ;

L= [ #'Input'= ] ; call struct(L) ;

L$([ 'Input' ]) =  L$([ 'Input' ]) || [ #"&amp;amp;VAR" = [ #a=, #b=, #c=]] ;
call struct(L) ;
L_I = L$'Input'$"&amp;amp;VAR" ; call struct(L_I ) ;


L$([ 'Input', "&amp;amp;VAR" ]) = L$([ 'Input', "&amp;amp;VAR" ]) || [ #"&amp;amp;MF"=[ #mf1=, #mf2=, #mf3=, #mf4=]] ;
call struct(L) ;
L_I_V = L$'Input'$"&amp;amp;VAR"$"&amp;amp;MF" ; call struct(L_I_V ) ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I noticed that the call struct( L ) command does not produce all of the sublist and items of the list L. How can I tell the struct() module to print the entire structure of the list? Are the parameters stored somewhere and can I use a list function to change them?&lt;/P&gt;</description>
    <pubDate>Fri, 22 Oct 2021 00:14:05 GMT</pubDate>
    <dc:creator>rbettinger</dc:creator>
    <dc:date>2021-10-22T00:14:05Z</dc:date>
    <item>
      <title>Two questions: Appending an item to a list, and using a variable in defining a list item</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Two-questions-Appending-an-item-to-a-list-and-using-a-variable/m-p/775513#M5704</link>
      <description>&lt;P&gt;Question 1: I want to append an item to a list. The code works in one case but not in another, and I can't figure out why the failure occurs. Here is the program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml ; package load listutil ;
L = [ #'Input'=[] ] ;
var = [ #'var1'='var1' ] ;
L$'Input' = L$'Input' || var ;
call struct( L ) ;
MF = [ #'MF'='MF' ] ;
L$'Input'$'var1' = L$'Input'$'var1' || MF ;
call struct( L ) ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The structure is the same in each case: create a list item, then append it to the parent list. The first case has one level, and the second has two levels. Why does the second case fail when the first case works? What is changed by adding another level?&lt;/P&gt;
&lt;P&gt;Question 2: If I want to build a list inside of a module with a varying item name under program control, how do I do this? Here is my example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml ; package load listutil ;
L = [ #'Input'=[] ] ;
var = 'var1' ;
L$'Input' = L$'Input' || [ var = 'variable item name' ] ;
call struct( L ) ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While the code executes correctly, the item name is 'Input[1]' instead of 'var1' and the value is 0 instead of 'variable item name' so I know that the variable 'var' is not resolved into 'var1' as the item name. How do I use a variable instead of a literal to allow me the flexibility that I want?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 20:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Two-questions-Appending-an-item-to-a-list-and-using-a-variable/m-p/775513#M5704</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-10-20T20:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Two questions: Appending an item to a list, and using a variable in defining a list item</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Two-questions-Appending-an-item-to-a-list-and-using-a-variable/m-p/775530#M5705</link>
      <description>&lt;P&gt;A1. In the first example,&amp;nbsp; L$'Input'&amp;nbsp; and var are both lists. So&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt; L$'Input' || var ;&lt;/LI-CODE&gt;
&lt;P&gt;is the concatenation of two lists.&lt;/P&gt;
&lt;P&gt;In the second example,&amp;nbsp;L$'Input'$'var1' is a character string and MF is a list. The operation&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;L$'Input'$'var1' || MF &lt;/LI-CODE&gt;
&lt;P&gt;is undefined. To resolve the issue, either enclose the left-hand argument in square brackets to make it a list, or use the $ operator to extract the character value from the right-hand argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A2:&amp;nbsp; The &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_013/imlug/imlug_lists_gettingstarted04.htm" target="_self"&gt;documentation for associative arrays&lt;/A&gt; says:&lt;/P&gt;
&lt;P&gt;"Specify the name of an item by prefixing it with the '#' symbol. You can specify the name as a &lt;EM&gt;character literal or as a quoted string.&lt;/EM&gt;" &lt;BR /&gt;Notice that it does not say that you can specify the name as the value of a character matrix, which seems to be what you are trying to do.&lt;/P&gt;
&lt;P&gt;There are two ways to deal with this issue:&lt;/P&gt;
&lt;P&gt;1. You can use &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_013/imlug/imlug_langref_sect248.htm" target="_self"&gt;the LISTSETNAME function&lt;/A&gt; to assign a name after you create the list.&lt;/P&gt;
&lt;P&gt;2. You can use SAS to write SAS code, so you can circumvent this limitation by using macro or CALL EXECUTE. If you choose this option, I suggest that you use&lt;A href="https://blogs.sas.com/content/iml/2011/10/17/does-symput-work-in-iml.html" target="_self"&gt; CALL SYMPUT&lt;/A&gt; for this.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Oct 2021 22:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Two-questions-Appending-an-item-to-a-list-and-using-a-variable/m-p/775530#M5705</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-10-20T22:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: Two questions: Appending an item to a list, and using a variable in defining a list item</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Two-questions-Appending-an-item-to-a-list-and-using-a-variable/m-p/775790#M5712</link>
      <description>&lt;P&gt;I had never thought to use SAS/MACRO within SAS/IML, but the CALL SYMPUT suggestion works just fine! Thank you very much, Rick.&lt;/P&gt;
&lt;P&gt;Here is my code. The first example does not use CALL SYMPUT, and the second one does, giving me the flexibility that I need.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml ; package load listutil ;
print 'this code does not use CALL SYMPUT' ;
L = [ #'Input' = ] ;
call struct(L) ; call listprint(L) ;

L$([ 'Input' ]) =  L$([ 'Input' ]) || [ #'Var1' = [ #a=, #b=, #c=]] ;
call struct(L) ; call listprint(L) ;

L$([ 'Input', 'Var1' ]) = L$([ 'Input', 'Var1' ]) || [ #'MF1'=[ #mf1=, #mf2=, #mf3=, #mf4=]] ;
call struct(L) ; call listprint(L$'Input'$'Var1') ;
L_I_V = L$'Input'$'Var1'$'MF1' ; call struct(L_I_V ) ;

print 'this code uses CALL SYMPUT' ;
call symput( 'VAR', "Var1" ) ;
call symput( 'MF' , 'MF1'  ) ;

L= [ #'Input'= ] ; call struct(L) ;

L$([ 'Input' ]) =  L$([ 'Input' ]) || [ #"&amp;amp;VAR" = [ #a=, #b=, #c=]] ;
call struct(L) ;
L_I = L$'Input'$"&amp;amp;VAR" ; call struct(L_I ) ;


L$([ 'Input', "&amp;amp;VAR" ]) = L$([ 'Input', "&amp;amp;VAR" ]) || [ #"&amp;amp;MF"=[ #mf1=, #mf2=, #mf3=, #mf4=]] ;
call struct(L) ;
L_I_V = L$'Input'$"&amp;amp;VAR"$"&amp;amp;MF" ; call struct(L_I_V ) ;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I noticed that the call struct( L ) command does not produce all of the sublist and items of the list L. How can I tell the struct() module to print the entire structure of the list? Are the parameters stored somewhere and can I use a list function to change them?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Oct 2021 00:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Two-questions-Appending-an-item-to-a-list-and-using-a-variable/m-p/775790#M5712</guid>
      <dc:creator>rbettinger</dc:creator>
      <dc:date>2021-10-22T00:14:05Z</dc:date>
    </item>
  </channel>
</rss>

