<?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: How to extract words from the string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681962#M206372</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/343672"&gt;@MSK4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;data have_2;&lt;BR /&gt;input company $40.;&lt;BR /&gt;cards;&lt;BR /&gt;Indian Business company&lt;BR /&gt;Ind school company&lt;BR /&gt;australia Business school company&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;i have tried but i haven't got output.i want output like this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Business&lt;/P&gt;
&lt;P&gt;school&lt;/P&gt;
&lt;P&gt;Business school&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use a DO loop from 2 to COUNTW - 1, extract the words with SCAN, and concatenate with CATX.&lt;/P&gt;</description>
    <pubDate>Mon, 07 Sep 2020 06:56:04 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-09-07T06:56:04Z</dc:date>
    <item>
      <title>How to extract words from string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681952#M206367</link>
      <description>&lt;P&gt;data have_1;&lt;BR /&gt;input company $40.;&lt;BR /&gt;cards;&lt;BR /&gt;Ind Business company&lt;BR /&gt;Ind school company&lt;BR /&gt;Ind Business school company&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want_1;&lt;BR /&gt;set have_1;&lt;BR /&gt;new=substr(company,5,findw(company,'company')-1-4);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this i got output what i expected&amp;nbsp; but the code seems to be not perfect&lt;/P&gt;&lt;P&gt;output&lt;/P&gt;&lt;P&gt;Business&lt;/P&gt;&lt;P&gt;school&lt;/P&gt;&lt;P&gt;Business school&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you please correct me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 05:16:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681952#M206367</guid>
      <dc:creator>MSK4</dc:creator>
      <dc:date>2020-09-07T05:16:33Z</dc:date>
    </item>
    <item>
      <title>How to extract words from the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681953#M206369</link>
      <description>&lt;P&gt;data have_2;&lt;BR /&gt;input company $40.;&lt;BR /&gt;cards;&lt;BR /&gt;Indian Business company&lt;BR /&gt;Ind school company&lt;BR /&gt;australia Business school company&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;i have tried but i haven't got output.i want output like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;Business&lt;/P&gt;&lt;P&gt;school&lt;/P&gt;&lt;P&gt;Business school&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 05:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681953#M206369</guid>
      <dc:creator>MSK4</dc:creator>
      <dc:date>2020-09-07T05:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract words from string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681959#M206370</link>
      <description>&lt;P&gt;Please don't double-post questions. I have merged both posts.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 06:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681959#M206370</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-09-07T06:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract words from the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681962#M206372</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/343672"&gt;@MSK4&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;data have_2;&lt;BR /&gt;input company $40.;&lt;BR /&gt;cards;&lt;BR /&gt;Indian Business company&lt;BR /&gt;Ind school company&lt;BR /&gt;australia Business school company&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;i have tried but i haven't got output.i want output like this&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Business&lt;/P&gt;
&lt;P&gt;school&lt;/P&gt;
&lt;P&gt;Business school&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use a DO loop from 2 to COUNTW - 1, extract the words with SCAN, and concatenate with CATX.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 06:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681962#M206372</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-07T06:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract words from string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681969#M206375</link>
      <description>&lt;P&gt;So, basically you want to drop the first word, which is nationality, and the word "company". Here is a solution using SCAN and CATX:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have_1;
  length new $40;
  do _N_=2 to countw(company) while (upcase(scan(company,_N_)) ne 'COMPANY');
    call catx(' ',new,scan(company,_N_));
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another possibility is to use Pearl regular expressions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have_1;
  new=prxchange('s/^\S*\s+//',1,company);
  new=prxchange('s/\s+company\b//i',1,new);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works slightly different, as any words after "company" are retained (if any) and the SCAN solution drops them. If you want to get rid of those as well with PRX, change the last expression to&amp;nbsp;&lt;CODE class=" language-sas"&gt;'s/\s+company\b.*//i'&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 08:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681969#M206375</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-09-07T08:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract words from string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681999#M206394</link>
      <description>&lt;P&gt;Can you explain in general what you expect to have as output given any input ?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 11:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-words-from-string/m-p/681999#M206394</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-09-07T11:42:23Z</dc:date>
    </item>
  </channel>
</rss>

