<?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: Return word number in a string in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Return-word-number-in-a-string/m-p/966218#M43292</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Annoyingly, it also doesn't consider a word that ends with punctuation, like "word." to be a word either&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is what the delimiter parameter is for.&amp;nbsp; Also consider the use of the I and T options.&amp;nbsp; And the S option is useful with T to make sure that the space does to get removed from the delimiter list.&lt;/P&gt;
&lt;PRE&gt;524  data example;
525    input string $50.;
526    word = 'word';
527    position = findw(string, word, '.?!,:;','site');
528    put position= string=;
529  datalines;

position=8 string=This is a sample string containing the word.
position=0 string=Another example without the keyword.
position=2 string=The word appears here.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 10 May 2025 00:44:57 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-05-10T00:44:57Z</dc:date>
    <item>
      <title>Return word number in a string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Return-word-number-in-a-string/m-p/966214#M43290</link>
      <description>&lt;P&gt;I am attempting to find the location of a word within a string, not the character position, but where in the string the word appears.&amp;nbsp; For example, the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data example;
    input string $50.;
    word = 'word';
    position = find(string, word);
    datalines;
This is a sample string containing the word.
Another example without the keyword.
The word appears here.
;
run;&lt;/PRE&gt;&lt;P&gt;Has the output of&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DumDum_0-1746832279010.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106850iF8095DBEA7669C3B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DumDum_0-1746832279010.png" alt="DumDum_0-1746832279010.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;However, the position I am seeking is:&lt;BR /&gt;OBS1 position 8&lt;BR /&gt;OBS2 position 0&lt;/P&gt;&lt;P&gt;OBS3 position 2&lt;BR /&gt;&lt;BR /&gt;Reason being the actual data will have wildcards scattered within the string that could be replaced with any number of characters and this value will later be used in a scan function to find specific matches in a delimited variable value.&lt;BR /&gt;&lt;BR /&gt;Hope that makes sense...&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2025 23:14:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Return-word-number-in-a-string/m-p/966214#M43290</guid>
      <dc:creator>DumDum</dc:creator>
      <dc:date>2025-05-09T23:14:44Z</dc:date>
    </item>
    <item>
      <title>Re: Return word number in a string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Return-word-number-in-a-string/m-p/966217#M43291</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
    input string $50.;
    word = 'word';
    position = findw(compress(string, '.,;!?'), word, ' ', 'e');
    datalines;
This is a sample string containing the word.
Another example without the keyword.
The word appears here.
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that this will only find whole words, so, for example, it won't find "word" in "keyword".&amp;nbsp; Annoyingly, it also doesn't consider a word that ends with punctuation, like "word." to be a word either - the compress part is a workaround for that.&lt;/P&gt;</description>
      <pubDate>Sat, 10 May 2025 00:35:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Return-word-number-in-a-string/m-p/966217#M43291</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-05-10T00:35:24Z</dc:date>
    </item>
    <item>
      <title>Re: Return word number in a string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Return-word-number-in-a-string/m-p/966218#M43292</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Annoyingly, it also doesn't consider a word that ends with punctuation, like "word." to be a word either&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is what the delimiter parameter is for.&amp;nbsp; Also consider the use of the I and T options.&amp;nbsp; And the S option is useful with T to make sure that the space does to get removed from the delimiter list.&lt;/P&gt;
&lt;PRE&gt;524  data example;
525    input string $50.;
526    word = 'word';
527    position = findw(string, word, '.?!,:;','site');
528    put position= string=;
529  datalines;

position=8 string=This is a sample string containing the word.
position=0 string=Another example without the keyword.
position=2 string=The word appears here.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 May 2025 00:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Return-word-number-in-a-string/m-p/966218#M43292</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-05-10T00:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Return word number in a string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Return-word-number-in-a-string/m-p/966229#M43293</link>
      <description>&lt;P&gt;Using E option to find nth word ,not the position of word,&lt;/P&gt;
&lt;P&gt;and using P option to add punctuation as a delimiter character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
    input string $50.;
    word = 'word';
    position = findw(string,strip(word),' ','p&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;e&lt;/STRONG&gt;&lt;/FONT&gt;');
    datalines;
This is a sample string containing the word.
Another example without the keyword.
The word appears here.
;
run;
proc print;run;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1746846696233.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106854i71DEB7A01D1BE294/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1746846696233.png" alt="Ksharp_0-1746846696233.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 May 2025 03:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Return-word-number-in-a-string/m-p/966229#M43293</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-05-10T03:11:47Z</dc:date>
    </item>
  </channel>
</rss>

