<?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 Extract a specific word in a character string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-specific-word-in-a-character-string/m-p/923812#M363673</link>
    <description>&lt;P&gt;How can I extract the specific "word" all the time? Indexw is only retrieving sometimes&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data original_data;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;infile datalines delimiter=',';&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; input txt $40. ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; datalines;&lt;/DIV&gt;
&lt;DIV&gt;166,181,410,333&lt;/DIV&gt;
&lt;DIV&gt;166,358&lt;/DIV&gt;
&lt;DIV&gt;166,181,105&lt;/DIV&gt;
&lt;DIV&gt;358&lt;/DIV&gt;
&lt;DIV&gt;166,181,250,105&lt;/DIV&gt;
&lt;DIV&gt;181,&lt;/DIV&gt;
&lt;DIV&gt;105,166&lt;/DIV&gt;
&lt;DIV&gt;;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data new_data;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; set original_data;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indexw_166 = indexw(txt, '166');&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indexw_181 = indexw(txt, '181');&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; indexw_358 = indexw(txt, '358');&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc print data=new_data;run;&lt;/DIV&gt;</description>
    <pubDate>Wed, 10 Apr 2024 14:44:06 GMT</pubDate>
    <dc:creator>Stalk</dc:creator>
    <dc:date>2024-04-10T14:44:06Z</dc:date>
    <item>
      <title>Extract a specific word in a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-specific-word-in-a-character-string/m-p/923812#M363673</link>
      <description>&lt;P&gt;How can I extract the specific "word" all the time? Indexw is only retrieving sometimes&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data original_data;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;infile datalines delimiter=',';&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; input txt $40. ;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; datalines;&lt;/DIV&gt;
&lt;DIV&gt;166,181,410,333&lt;/DIV&gt;
&lt;DIV&gt;166,358&lt;/DIV&gt;
&lt;DIV&gt;166,181,105&lt;/DIV&gt;
&lt;DIV&gt;358&lt;/DIV&gt;
&lt;DIV&gt;166,181,250,105&lt;/DIV&gt;
&lt;DIV&gt;181,&lt;/DIV&gt;
&lt;DIV&gt;105,166&lt;/DIV&gt;
&lt;DIV&gt;;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data new_data;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; set original_data;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indexw_166 = indexw(txt, '166');&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indexw_181 = indexw(txt, '181');&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; indexw_358 = indexw(txt, '358');&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc print data=new_data;run;&lt;/DIV&gt;</description>
      <pubDate>Wed, 10 Apr 2024 14:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-a-specific-word-in-a-character-string/m-p/923812#M363673</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2024-04-10T14:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a specific word in a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-specific-word-in-a-character-string/m-p/923817#M363674</link>
      <description>&lt;P&gt;It would help if you told it what delimiter(s) to use.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data original_data;
  input txt $40. ;
  indexw_166 = indexw(txt, '166',', ');
  indexw_181 = indexw(txt, '181',', ');
  indexw_358 = indexw(txt, '358',', ');
datalines;
166,181,410,333
166,358
166,181,105
358
166,181,250,105
181,
105,166
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;                          indexw_    indexw_    indexw_
Obs    txt                  166        181        358

 1     166,181,410,333       1          5          0
 2     166,358               1          0          5
 3     166,181,105           1          5          0
 4     358                   0          0          1
 5     166,181,250,105       1          5          0
 6     181,                  0          1          0
 7     105,166               5          0          0
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;And if the goal is to "extract" then perhaps you might want to use the FINDW() function instead.&amp;nbsp; With the E modifier it will return the word number instead of the first character position.&amp;nbsp; You can then use that with SCAN() to "extract" the word.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data original_data;
  input txt $40. ;
  indexw_166 = indexw(txt, '166',', ');
  indexw_181 = indexw(txt, '181',', ');
  indexw_358 = indexw(txt, '358',', ');
  loc_166=findw(txt,'166',',','er');
  value_166 = scan(txt,loc_166,',');
datalines;
166,181,410,333
166,358
166,181,105
358
166,181,250,105
181,
105,166
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;                          indexw_    indexw_    indexw_               value_
Obs    txt                  166        181        358      loc_166     166

 1     166,181,410,333       1          5          0          1        166
 2     166,358               1          0          5          1        166
 3     166,181,105           1          5          0          1        166
 4     358                   0          0          1          0
 5     166,181,250,105       1          5          0          1        166
 6     181,                  0          1          0          0
 7     105,166               5          0          0          0
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 15:25:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-a-specific-word-in-a-character-string/m-p/923817#M363674</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-10T15:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a specific word in a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-a-specific-word-in-a-character-string/m-p/923830#M363678</link>
      <description>Thank you for the quick solution</description>
      <pubDate>Wed, 10 Apr 2024 15:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-a-specific-word-in-a-character-string/m-p/923830#M363678</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2024-04-10T15:26:03Z</dc:date>
    </item>
  </channel>
</rss>

