<?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: Identifying patterns in a character string in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204572#M4566</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You will have to loop over your string, pull out word for word and then compare it with a reference table. As for punctuation in strings and whether to treat them as word delimiters or as part of the string will depend on your reference table to compare with. Will something like "Ltd." also have a dot at the end? Or will you have all possible versions in this list?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below a code sample which creates and uses a SAS format for the comparison.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data wordlist;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input word:$20.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;Company&lt;/P&gt;&lt;P&gt;Ltd&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data cntlin_source;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain fmtname 'MatchWords' type 'c';&lt;/P&gt;&lt;P&gt;&amp;nbsp; set wordlist(rename=(word=start)) end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp; start=upcase(start);&lt;/P&gt;&lt;P&gt;&amp;nbsp; label='1';&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last then &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hlo='O';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label='0';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format cntlin=cntlin_source;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input string $60.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;this is an a sample string with no match&lt;/P&gt;&lt;P&gt;string with company ltd. in text&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data matching_words(drop=_:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; source_obs=_n_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length word $40.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _stop=countw(string,' .');&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _i=1 to _stop;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; word=scan(string,_i,' .');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if put(upcase(word),$MatchWords.)='1' then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 22 Aug 2015 23:04:28 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2015-08-22T23:04:28Z</dc:date>
    <item>
      <title>Identifying patterns in a character string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204565#M4559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a variable with company names in it. I would like to identify all the observations which have some specific words in the company name. This list of words are in a separate file and are almost 30,000. Is there an efficient way to do this? Would appreciate any assistance. Thanks. Harvey&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Aug 2015 14:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204565#M4559</guid>
      <dc:creator>harvey7415</dc:creator>
      <dc:date>2015-08-21T14:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying patterns in a character string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204566#M4560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could load the words into a temporary array and&amp;nbsp; then loop through them.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Aug 2015 14:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204566#M4560</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-08-21T14:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying patterns in a character string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204567#M4561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is specific case an issue: Example would word Ltd&amp;nbsp; match in a name like Company LTD ?&lt;/P&gt;&lt;P&gt;What about substrings: word Engineer&amp;nbsp;&amp;nbsp; and company ABC Engineering&lt;/P&gt;&lt;P&gt;or component:&amp;nbsp; word Engineering&amp;nbsp;&amp;nbsp; and company Engineer Contracting&lt;/P&gt;&lt;P&gt;Do your words contain punctuation such as Ltd.&amp;nbsp;&amp;nbsp; would the period have to match for Some Name, Ltd ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Aug 2015 16:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204567#M4561</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-08-21T16:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying patterns in a character string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204568#M4562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't care about the specific case. If it is LtD or ltd, I would like these observations identified.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some words in my list may have a punctuation mark like O'Reilly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am looking for exact word matches. So if the company name is Engineering and the word name is Engineer, I would like that observation&amp;nbsp; to be flagged off. &lt;/P&gt;&lt;P&gt;But if word name is Engineering and company name has Engineer in it, then I don't want them to be lagged off.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Aug 2015 17:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204568#M4562</guid>
      <dc:creator>harvey7415</dc:creator>
      <dc:date>2015-08-21T17:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying patterns in a character string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204569#M4563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your question is something which comes up regularly in this forum in one variation or another. Did you already try a search using something like "find word in string" or something similar?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Aug 2015 01:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204569#M4563</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-08-22T01:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying patterns in a character string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204570#M4564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have. I know there are plenty of solutions available if you need to identify one or two words in a string. That's easy. But how does one search 30,000 possible words that might appear in a character string? I am just looking for an efficient way of doing it?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Aug 2015 02:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204570#M4564</guid>
      <dc:creator>harvey7415</dc:creator>
      <dc:date>2015-08-22T02:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying patterns in a character string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204571#M4565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use SQL's cartesian product + findw() &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Aug 2015 05:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204571#M4565</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-08-22T05:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying patterns in a character string</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204572#M4566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You will have to loop over your string, pull out word for word and then compare it with a reference table. As for punctuation in strings and whether to treat them as word delimiters or as part of the string will depend on your reference table to compare with. Will something like "Ltd." also have a dot at the end? Or will you have all possible versions in this list?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below a code sample which creates and uses a SAS format for the comparison.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data wordlist;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input word:$20.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;Company&lt;/P&gt;&lt;P&gt;Ltd&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data cntlin_source;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain fmtname 'MatchWords' type 'c';&lt;/P&gt;&lt;P&gt;&amp;nbsp; set wordlist(rename=(word=start)) end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp; start=upcase(start);&lt;/P&gt;&lt;P&gt;&amp;nbsp; label='1';&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last then &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hlo='O';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label='0';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format cntlin=cntlin_source;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input string $60.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;this is an a sample string with no match&lt;/P&gt;&lt;P&gt;string with company ltd. in text&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data matching_words(drop=_:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; source_obs=_n_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length word $40.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; _stop=countw(string,' .');&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _i=1 to _stop;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; word=scan(string,_i,' .');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if put(upcase(word),$MatchWords.)='1' then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Aug 2015 23:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Identifying-patterns-in-a-character-string/m-p/204572#M4566</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-08-22T23:04:28Z</dc:date>
    </item>
  </channel>
</rss>

