<?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: find first location of character in string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443264#M110879</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;'s code with a tweak to&amp;nbsp;stop looping once a word&amp;nbsp;has been&amp;nbsp;found.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  Vector='0,0,5,11,9,10';
  _n=countw(vector,',');
  do _i=1 to _n;
    if input(scan(vector,_i,','),best.) &amp;gt; 0 then
      do;
        word=_i;
        leave;
      end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Mar 2018 12:29:17 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2018-03-07T12:29:17Z</dc:date>
    <item>
      <title>find first location of character in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443229#M110872</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I want to find first location of character in string.&lt;/P&gt;&lt;P&gt;Lets say I have the following data.&lt;/P&gt;&lt;P&gt;Vector='0,0,5,11,9,10'&lt;/P&gt;&lt;P&gt;I want to find the first location (after comma) where the number is different than 0.&lt;/P&gt;&lt;P&gt;In this case the answer is &amp;nbsp;3 &amp;nbsp;because the third argument in vector has value different than 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I calculate it in SAS &amp;nbsp;please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;Ronein&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 10:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443229#M110872</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-03-07T10:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: find first location of character in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443233#M110874</link>
      <description>&lt;PRE&gt;data want (drop=i);
  Vector='0,0,5,11,9,10';
  do i=1 to countw(vector,',');
    if input(scan(vector,i,','),best.) &amp;gt; 0 and word = . then word=i;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 10:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443233#M110874</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-07T10:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: find first location of character in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443264#M110879</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;'s code with a tweak to&amp;nbsp;stop looping once a word&amp;nbsp;has been&amp;nbsp;found.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  Vector='0,0,5,11,9,10';
  _n=countw(vector,',');
  do _i=1 to _n;
    if input(scan(vector,_i,','),best.) &amp;gt; 0 then
      do;
        word=_i;
        leave;
      end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Mar 2018 12:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443264#M110879</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-07T12:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: find first location of character in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443284#M110888</link>
      <description>&lt;P&gt;Quite true, but then you would only need:&lt;/P&gt;
&lt;PRE&gt;data want;
  vector='0,0,5,11,9,10';
  do word=1 to countw(vector,',');
    if input(scan(vector,word,','),best.) &amp;gt; 0 then leave;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;As word gets incremented up to the point where the loop is exited.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 13:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443284#M110888</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-07T13:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: find first location of character in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443294#M110889</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;And what's the value of &lt;EM&gt;Word&lt;/EM&gt; if the condition never gets True?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 13:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443294#M110889</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-07T13:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: find first location of character in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443302#M110892</link>
      <description>&lt;P&gt;True, I had assumed there would always be one non-zero.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 14:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443302#M110892</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-07T14:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: find first location of character in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443309#M110895</link>
      <description>&lt;P&gt;This is one of the occasions where PRX is really good:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  Vector='0,0,5,11,9,10';
  pos=prxmatch('/\b[1-9]/',Vector);
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;A short explanation of the search string: \b means a word boundary (could be your comma, or the beginning of the string), [1-9] means one of the digits 1 to 9. If there is no match, the function returns 0.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 14:13:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443309#M110895</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-03-07T14:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: find first location of character in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443311#M110896</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;This is one of the occasions where PRX is really good:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  Vector='0,0,5,11,9,10';
  pos=prxmatch('/\b[1-9]/',Vector);
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A short explanation of the search string: \b means a word boundary (could be your comma, or the beginning of the string), [1-9] means one of the digits 1 to 9. If there is no match, the function returns 0.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;...except that it returns 5 instead of 3. The OP asks for the number of the Word (3rd word) and not the start position in the string.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 14:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-first-location-of-character-in-string/m-p/443311#M110896</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-07T14:16:53Z</dc:date>
    </item>
  </channel>
</rss>

