<?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: How to get the variable by index from a macro variable list? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519677#M3844</link>
    <description>&lt;P&gt;Thank you so much.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 08 Dec 2018 19:31:41 GMT</pubDate>
    <dc:creator>Shone</dc:creator>
    <dc:date>2018-12-08T19:31:41Z</dc:date>
    <item>
      <title>How to get the variable by index from a macro variable list?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519656#M3838</link>
      <description>&lt;P&gt;How can I get the variable of a macro using index?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%vars = apple ball cats ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I get apple ball or cat based on index?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have convert it to table and use proc sql to get the variables.&amp;nbsp; Is there any way to get variable based on index without&amp;nbsp; converting it to table and using proc sql?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could easily do vars[0] to get apple and vars [2] to get cats in python.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Shone&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 16:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519656#M3838</guid>
      <dc:creator>Shone</dc:creator>
      <dc:date>2018-12-08T16:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the variable by index from a macro variable list?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519662#M3839</link>
      <description>&lt;P&gt;Since all you have done is assign a string of characters to a macro variable you do not have a "list" or an "array" so your Python example is off base.&amp;nbsp; If you want to interpret that string as a space delimited list then use the %scan() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=apple ball cats ;
%let i=1 ;
%let item=%scan(&amp;amp;list,&amp;amp;i,%str( ));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Dec 2018 17:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519662#M3839</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-08T17:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the variable by index from a macro variable list?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519663#M3840</link>
      <description>Thank you so much. I was looking it in wrong way. If given the var list above, how can I get the max index of that list?</description>
      <pubDate>Sat, 08 Dec 2018 17:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519663#M3840</guid>
      <dc:creator>Shone</dc:creator>
      <dc:date>2018-12-08T17:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the variable by index from a macro variable list?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519664#M3841</link>
      <description>&lt;P&gt;Sorry but how would you get the rest of item except the item from given index? For instance, if we give 1 we want ball and cat.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 18:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519664#M3841</guid>
      <dc:creator>Shone</dc:creator>
      <dc:date>2018-12-08T18:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the variable by index from a macro variable list?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519673#M3842</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250177"&gt;@Shone&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you so much. I was looking it in wrong way. If given the var list above, how can I get the max index of that list?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To find how many words are in a delimited list use the COUNTW() function. To use that it macro code use the %SYSFUNC() macro function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let n=%sysfunc(countw(a b c,%str( )));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will set N to 3.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 19:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519673#M3842</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-08T19:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the variable by index from a macro variable list?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519674#M3843</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250177"&gt;@Shone&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry but how would you get the rest of item except the item from given index? For instance, if we give 1 we want ball and cat.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I cannot think of an case where that would be useful. The main purpose of macro code is to generate code. So perhaps you could generate code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where findw("&amp;amp;list",x,' ','t')
  and x ne "%scan(&amp;amp;list,&amp;amp;i,%str( ))"
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if X is in the list but not equal to the i-th item in the list.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 19:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519674#M3843</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-08T19:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the variable by index from a macro variable list?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519677#M3844</link>
      <description>&lt;P&gt;Thank you so much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 19:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-the-variable-by-index-from-a-macro-variable-list/m-p/519677#M3844</guid>
      <dc:creator>Shone</dc:creator>
      <dc:date>2018-12-08T19:31:41Z</dc:date>
    </item>
  </channel>
</rss>

