<?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 How to find a given word in a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895644#M353866</link>
    <description>&lt;P&gt;I have an example dataset as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
  input InvestorID Type &amp;amp; $char1000.;
  length Type $1000;
DATALINES;
1001 Accelerator/Incubator 
1002 Accelerator/Incubator, Angel (individual), Angel Group, Asset Manager, Business Development Company, Corporate Development, Corporate Venture Capital, Corporation, Family Office, Fund of Funds, Fundless Sponsor, Government, Growth/Expansion, Hedge Fund, Holding Company, Impact Investing, Infrastructure, Investment Bank, Leasing, Lender/Debt Provider, Limited Partner, Merchant Banking Firm, Mezzanine, Mutual Fund, Not-For-Profit Venture Capital, Other Private Equity, PE-Backed Company, PE/Buyout, Real Estate, SBIC, Secondary Buyer, Sovereign Wealth Fund, University, VC-Backed Company, Venture Capital 
1003 Accelerator/Incubator, Angel (individual), Business Development Company, Venture Capital 
1004 Corporate Venture Capital, Fund of Funds 
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What I want to do is produce the following dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want;
  input InvestorID Type &amp;amp; $char1000. CVC VC;
  length Type $1000;
DATALINES;
1001 Accelerator/Incubator  0 0
1002 Accelerator/Incubator, Angel (individual), Angel Group, Asset Manager, Business Development Company, Corporate Development, Corporate Venture Capital, Corporation, Family Office, Fund of Funds, Fundless Sponsor, Government, Growth/Expansion, Hedge Fund, Holding Company, Impact Investing, Infrastructure, Investment Bank, Leasing, Lender/Debt Provider, Limited Partner, Merchant Banking Firm, Mezzanine, Mutual Fund, Not-For-Profit Venture Capital, Other Private Equity, PE-Backed Company, PE/Buyout, Real Estate, SBIC, Secondary Buyer, Sovereign Wealth Fund, University, VC-Backed Company, Venture Capital  1 1
1003 Accelerator/Incubator, Angel (individual), Business Development Company, Venture Capital  0 1
1004 Corporate Venture Capital, Fund of Funds  1 0
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The CVC variable takes on a value of 1 if in Type, the word Corporate Venture Capital appears, otherwise it is 0. Likewise the VC variable takes on a value of 1 if in Type, the word Venture Capital appears, otherwise it is 0. These words Corporate Venture Capital and Venture Capital are always spelt with the same capitalization.&lt;/P&gt;</description>
    <pubDate>Mon, 25 Sep 2023 10:52:58 GMT</pubDate>
    <dc:creator>elbarto</dc:creator>
    <dc:date>2023-09-25T10:52:58Z</dc:date>
    <item>
      <title>How to find a given word in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895644#M353866</link>
      <description>&lt;P&gt;I have an example dataset as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
  input InvestorID Type &amp;amp; $char1000.;
  length Type $1000;
DATALINES;
1001 Accelerator/Incubator 
1002 Accelerator/Incubator, Angel (individual), Angel Group, Asset Manager, Business Development Company, Corporate Development, Corporate Venture Capital, Corporation, Family Office, Fund of Funds, Fundless Sponsor, Government, Growth/Expansion, Hedge Fund, Holding Company, Impact Investing, Infrastructure, Investment Bank, Leasing, Lender/Debt Provider, Limited Partner, Merchant Banking Firm, Mezzanine, Mutual Fund, Not-For-Profit Venture Capital, Other Private Equity, PE-Backed Company, PE/Buyout, Real Estate, SBIC, Secondary Buyer, Sovereign Wealth Fund, University, VC-Backed Company, Venture Capital 
1003 Accelerator/Incubator, Angel (individual), Business Development Company, Venture Capital 
1004 Corporate Venture Capital, Fund of Funds 
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What I want to do is produce the following dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want;
  input InvestorID Type &amp;amp; $char1000. CVC VC;
  length Type $1000;
DATALINES;
1001 Accelerator/Incubator  0 0
1002 Accelerator/Incubator, Angel (individual), Angel Group, Asset Manager, Business Development Company, Corporate Development, Corporate Venture Capital, Corporation, Family Office, Fund of Funds, Fundless Sponsor, Government, Growth/Expansion, Hedge Fund, Holding Company, Impact Investing, Infrastructure, Investment Bank, Leasing, Lender/Debt Provider, Limited Partner, Merchant Banking Firm, Mezzanine, Mutual Fund, Not-For-Profit Venture Capital, Other Private Equity, PE-Backed Company, PE/Buyout, Real Estate, SBIC, Secondary Buyer, Sovereign Wealth Fund, University, VC-Backed Company, Venture Capital  1 1
1003 Accelerator/Incubator, Angel (individual), Business Development Company, Venture Capital  0 1
1004 Corporate Venture Capital, Fund of Funds  1 0
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The CVC variable takes on a value of 1 if in Type, the word Corporate Venture Capital appears, otherwise it is 0. Likewise the VC variable takes on a value of 1 if in Type, the word Venture Capital appears, otherwise it is 0. These words Corporate Venture Capital and Venture Capital are always spelt with the same capitalization.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 10:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895644#M353866</guid>
      <dc:creator>elbarto</dc:creator>
      <dc:date>2023-09-25T10:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a given word in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895646#M353867</link>
      <description>&lt;P&gt;I ask for clarification. In several places in your text, you indicate you are looking for a "word", but then the search strings are made up of several words, such as "&lt;SPAN&gt;Corporate Venture Capital". Are we searching for one of these words, or do we have to find all of "Corporate Venture Capital" to get a match?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2023 11:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895646#M353867</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-25T11:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a given word in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895806#M353927</link>
      <description>&lt;P&gt;Sorry, I mean the entire string "Corporate Venture Capital" to get a match. Likewise for the entire string "Venture Capital".&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 00:46:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895806#M353927</guid>
      <dc:creator>elbarto</dc:creator>
      <dc:date>2023-09-26T00:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a given word in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895821#M353930</link>
      <description>&lt;P&gt;If you just want to find the string, even if it is part of a longer word, then use INDEX() or FIND().&amp;nbsp; If you want to only find it when it is a stand only word (or phrase in this case) then use INDEXW() or FINDW().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of those functions return the location the value was found. Which you could treat as TRUE or FALSE since SAS considers any number other than zero or missing as TRUE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could just add a simple comparison operator to force it to be a true 0/1 boolean value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another advantage of the FIND() and FINDW() function is that they accept modifiers to allow you to ignore case and/or trim leading/trailing delimiters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CVC = 0 &amp;lt; indexw(Type,'Corporate Venture Capital');
CV= 0 &amp;lt; indexw(Type,'Venture Capital');
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 03:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895821#M353930</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-26T03:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a given word in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895828#M353935</link>
      <description>&lt;P&gt;Thank you. However, when I try the following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
CVC = 0 &amp;lt; indexw(Type,'Corporate Venture Capital');
VC= 0 &amp;lt; indexw(Type,'Venture Capital');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It does not seem to be picking up the "Corporate Venture Capital", for example, CVC is 0 for both investorID=1002 and 1004, when it should be 1.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 05:07:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895828#M353935</guid>
      <dc:creator>elbarto</dc:creator>
      <dc:date>2023-09-26T05:07:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a given word in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895833#M353937</link>
      <description>&lt;P&gt;Does below work for you?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
  input InvestorID Type &amp;amp; $char1000. CVC_want VC_want;
  length Type $1000;
DATALINES;
1001 Accelerator/Incubator  0 0
1002 Accelerator/Incubator, Angel (individual), Angel Group, Asset Manager, Business Development Company, Corporate Development, Corporate Venture Capital, Corporation, Family Office, Fund of Funds, Fundless Sponsor, Government, Growth/Expansion, Hedge Fund, Holding Company, Impact Investing, Infrastructure, Investment Bank, Leasing, Lender/Debt Provider, Limited Partner, Merchant Banking Firm, Mezzanine, Mutual Fund, Not-For-Profit Venture Capital, Other Private Equity, PE-Backed Company, PE/Buyout, Real Estate, SBIC, Secondary Buyer, Sovereign Wealth Fund, University, VC-Backed Company, Venture Capital  1 1
1003 Accelerator/Incubator, Angel (individual), Business Development Company, Venture Capital  0 1
1004 Corporate Venture Capital, Fund of Funds  1 0
;

data want;
  set have;
  cvc= find(type,'Corporate Venture Capital','i')&amp;gt;0;
  cv= prxmatch('/(?&amp;lt;!Corporate )Venture Capital/i',strip(type))&amp;gt;0;
run;

proc print data=want(drop=type);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1695707325766.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88331iC8F10447842587F0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1695707325766.png" alt="Patrick_0-1695707325766.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 05:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895833#M353937</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-09-26T05:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a given word in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895838#M353941</link>
      <description>&lt;P&gt;Thanks that works! I also tried the following, which works as well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;type_nc = compress(type);
CVC = 0 &amp;lt; indexw(type_nc,'CorporateVentureCapital',", ");
VC = 0 &amp;lt; indexw(type_nc,'VentureCapital',", ");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Sep 2023 06:45:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895838#M353941</guid>
      <dc:creator>elbarto</dc:creator>
      <dc:date>2023-09-26T06:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a given word in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895880#M353951</link>
      <description>&lt;P&gt;You have to tell INDEXW() what characters constituent end of a word.&amp;nbsp; Or just use INDEX() instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
  input InvestorID Type &amp;amp; $1000.;
  CVC = 0 &amp;lt; indexw(Type,'Corporate Venture Capital',' ,.()');
  VC= 0 &amp;lt; indexw(Type,'Venture Capital',' ,.()');
DATALINES;
1001 Accelerator/Incubator 
1002 Accelerator/Incubator, Angel (individual), Angel Group, Asset Manager, Business Development Company, Corporate Development, Corporate Venture Capital, Corporation, Family Office, Fund of Funds, Fundless Sponsor, Government, Growth/Expansion, Hedge Fund, Holding Company, Impact Investing, Infrastructure, Investment Bank, Leasing, Lender/Debt Provider, Limited Partner, Merchant Banking Firm, Mezzanine, Mutual Fund, Not-For-Profit Venture Capital, Other Private Equity, PE-Backed Company, PE/Buyout, Real Estate, SBIC, Secondary Buyer, Sovereign Wealth Fund, University, VC-Backed Company, Venture Capital 
1003 Accelerator/Incubator, Angel (individual), Business Development Company, Venture Capital 
1004 Corporate Venture Capital, Fund of Funds 
;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1695730132923.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88352iC25FB43C79E0AA32/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1695730132923.png" alt="Tom_0-1695730132923.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 12:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895880#M353951</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-26T12:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to find a given word in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895901#M353966</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/303550"&gt;@elbarto&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Whichever method you use, searching through a 1000-character string can be time-consuming.&amp;nbsp; If speed is an issue, you can probably speed things up by taking advantage of the fact that "Venture Capital" is a subset of "Corporate Venture Capital".&amp;nbsp; Consider this structure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;VC = (whatever method you choose);
if VC then CVC = (whatever method you choose);
else CVC = 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This avoids searching for "Corporate Venture Capital" in cases where it definitely won't exist.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 14:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-a-given-word-in-a-string/m-p/895901#M353966</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-09-26T14:02:18Z</dc:date>
    </item>
  </channel>
</rss>

