<?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: Search for last Value in numeric or character array in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797688#M33063</link>
    <description>Thank you for taking the time to help me &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Mon, 21 Feb 2022 23:42:10 GMT</pubDate>
    <dc:creator>Gablz</dc:creator>
    <dc:date>2022-02-21T23:42:10Z</dc:date>
    <item>
      <title>Search for last Value in numeric or character array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797586#M33053</link>
      <description>&lt;P&gt;Hey guys&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an array and it contains a few variables. Now there are some contents inside of those variables that are occuring more than once. I want to know at which Position the last occuring value inside those variables is. I know that you can search with whichn but i dont want the program to return the first matching variable but the last one. Is there a way i can do this?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Feb 2022 12:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797586#M33053</guid>
      <dc:creator>Gablz</dc:creator>
      <dc:date>2022-02-21T12:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: Search for last Value in numeric or character array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797592#M33055</link>
      <description>&lt;P&gt;Have you considered using the SCAN() function and searing from right to left? See the example "&lt;FONT size="4"&gt;Example 1: Using the SCAN Function in SAS and CAS" at this page:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/1.0/lefunctionsref/p0jshdjy2z9zdzn1h7k90u99lyq6.htm" target="_blank"&gt;SAS Help Center: SCAN Function&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Feb 2022 13:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797592#M33055</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2022-02-21T13:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Search for last Value in numeric or character array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797595#M33056</link>
      <description>Thanks for your proposal. But i understand the SCAN function the following way: The program gives you the value inside of what i define it to look for. But i only want him to give me the position at which the last numeric value is inside of my array. Can i do that too with SCAN and which example of your source (1,2,3,4 or 5) shows that? Im trying to understand what is done there and how i could use it to solve my problem</description>
      <pubDate>Mon, 21 Feb 2022 13:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797595#M33056</guid>
      <dc:creator>Gablz</dc:creator>
      <dc:date>2022-02-21T13:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Search for last Value in numeric or character array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797598#M33057</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/403188"&gt;@Gablz&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/403188"&gt;@Gablz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I know that you can search with whichn but i dont want the program to return the first matching variable but the last one. Is there a way i can do this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To make WHICHN return the position of the&amp;nbsp;&lt;EM&gt;last&lt;/EM&gt; occurrence of the value of interest, just create the array with reversed order of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data have;
input a b c d e f;
cards;
3 1 4 1 5 9
;&lt;/PRE&gt;
&lt;P&gt;Task: Determine the position and the name of the variable containing the last 1.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_p);
set have;
array v[*] f e d c b a;
length varname $32;
_p=whichn(1, of v[*]);
if _p then do;
  position=dim(v)-_p+1;
  varname=vname(v[_p]);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;a    b    c    d    e    f    &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;varname    position&lt;/FONT&gt;&lt;/STRONG&gt;

3    1    4    1    5    9     &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;  d           4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With similar coding effort you could use a DO loop to traverse the array &lt;FONT face="courier new,courier"&gt;x[*] a--f&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Feb 2022 14:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797598#M33057</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-02-21T14:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Search for last Value in numeric or character array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797600#M33058</link>
      <description>Thanks that works &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 21 Feb 2022 14:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797600#M33058</guid>
      <dc:creator>Gablz</dc:creator>
      <dc:date>2022-02-21T14:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Search for last Value in numeric or character array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797672#M33060</link>
      <description>&lt;P&gt;It may not be intuitive but if you define an array in reverse order then value associated with whichn from the reverse order array would be the LAST in the first array. Though that might get a bit confusing in actual use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   input v1- v5;
   array a (*) v1-v5;
   array z (*) v5-v1;
   zz = whichn(1,of z(*));
   znum = z[whichn(1,of z(*))];
datalines;
2 1 6 3 1
;&lt;/PRE&gt;
&lt;P&gt;ZZ has the position in the reversed array, 1 and finds the "last" value of 1 in the 5 variables.&lt;/P&gt;
&lt;P&gt;So the question might be which is more important to find, the Value of the variable or the position?&lt;/P&gt;
&lt;P&gt;You can add your own Whichn using the A array to compare.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Feb 2022 22:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797672#M33060</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-21T22:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Search for last Value in numeric or character array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797683#M33061</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/403188"&gt;@Gablz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hey guys&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have an array and it contains a few variables. Now there are some contents inside of those variables that are occuring more than once. I want to know at which Position the last occuring value inside those variables is. I know that you can search with whichn but i dont want the program to return the first matching variable but the last one. Is there a way i can do this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just list the variables in the opposite order.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  first5 = whichn(5, of var1-var5);
  last5 = whichn(5, of var5-var1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Feb 2022 23:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797683#M33061</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-21T23:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Search for last Value in numeric or character array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797687#M33062</link>
      <description>Thank you for your answer! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 21 Feb 2022 23:41:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797687#M33062</guid>
      <dc:creator>Gablz</dc:creator>
      <dc:date>2022-02-21T23:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Search for last Value in numeric or character array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797688#M33063</link>
      <description>Thank you for taking the time to help me &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 21 Feb 2022 23:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Search-for-last-Value-in-numeric-or-character-array/m-p/797688#M33063</guid>
      <dc:creator>Gablz</dc:creator>
      <dc:date>2022-02-21T23:42:10Z</dc:date>
    </item>
  </channel>
</rss>

