<?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: Array in Function, Reference a subset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-in-Function-Reference-a-subset/m-p/79379#M17128</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've ended up doing the DO loop method just to be safe. Would love to use the OF syntax though if it ever comes. Thanks for the input.&lt;/P&gt;&lt;P&gt;do _i=2 to nTokens;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastN= catx(' ', lastN, token{_i});&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Jul 2013 22:55:04 GMT</pubDate>
    <dc:creator>bob_pearson</dc:creator>
    <dc:date>2013-07-15T22:55:04Z</dc:date>
    <item>
      <title>Array in Function, Reference a subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-in-Function-Reference-a-subset/m-p/79376#M17125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to reference a subset of an array in a function call? The code below is a stripped down version of what I'm working with. What I'm looking for is something like the commented out LastN assignments at the bottom, which I know don't work. The number of tokens may vary, so the hard-coded reference in the uncommented LastN won't do it. I can loop through the last N words and sequentially add one token at a time, but I thought there might be a more direct method using the OF operator such as in the "all" assignment. Any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;data a;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input string $30.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;adam doug bob craig&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;pete repeat george regeorge&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;data b;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set a;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _n_=1 then do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array token {9} $15 _temporary_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ** other stuff;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nTokens = countw(string);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do _i=1 to nTokens;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; token[_i] = scan(string, _i);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; first = token{1};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; all = catx('-', of token&lt;LI&gt;);&lt;/LI&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastN = catx('-', token{2}, token{3}, token{4})&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;*&amp;nbsp;&amp;nbsp;&amp;nbsp; lastN2 = catx('-', of token{2:4});&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;*&amp;nbsp;&amp;nbsp;&amp;nbsp; lastN3 = catx('-', of token{2}-token{4});&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 17:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-in-Function-Reference-a-subset/m-p/79376#M17125</guid>
      <dc:creator>bob_pearson</dc:creator>
      <dc:date>2013-07-15T17:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Array in Function, Reference a subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-in-Function-Reference-a-subset/m-p/79377#M17126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is surprising that TOKEN&lt;LI&gt; works, but the others don't.&amp;nbsp; At any rate, you can construct LASTN based on ALL:&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lastN4 = catx('-', scan(all, '-', -3), scan(all, '-', -2), scan(all, '-', -1));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That should work, as long as none of the tokens contain a dash.&amp;nbsp; That shouldn't be a problem, seeing how the individual tokens are created by SCAN with the default set of delimiters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally, BEWARE.&amp;nbsp; Your code will give you the wrong result when the number of tokens decreases from one observation to the next.&amp;nbsp; In a temporary array, the values are automatically retained.&amp;nbsp; So with 4 tokens on the current observation, you will still have the retained value for token[5] if a value was assigned on any previous observation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 18:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-in-Function-Reference-a-subset/m-p/79377#M17126</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-07-15T18:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Array in Function, Reference a subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-in-Function-Reference-a-subset/m-p/79378#M17127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;Astounding wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;It is surprising that TOKEN&lt;LI&gt; works, but the others don't.&amp;nbsp; At any rate, you can construct LASTN based on ALL:&lt;/LI&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P style="padding: 0px; min-height: 8pt;"&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually it's not all surprising that (of array-name&lt;LI&gt;) works because that is a kind of SAS variable list. I believe the feature for temporary arrays was added in 9.2.&amp;nbsp; It would be nice if the other forms worked in OF lists.&amp;nbsp;&amp;nbsp; Probably something to do with compile vs execute. &lt;/LI&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 19:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-in-Function-Reference-a-subset/m-p/79378#M17127</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-07-15T19:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: Array in Function, Reference a subset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-in-Function-Reference-a-subset/m-p/79379#M17128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've ended up doing the DO loop method just to be safe. Would love to use the OF syntax though if it ever comes. Thanks for the input.&lt;/P&gt;&lt;P&gt;do _i=2 to nTokens;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastN= catx(' ', lastN, token{_i});&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jul 2013 22:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-in-Function-Reference-a-subset/m-p/79379#M17128</guid>
      <dc:creator>bob_pearson</dc:creator>
      <dc:date>2013-07-15T22:55:04Z</dc:date>
    </item>
  </channel>
</rss>

