<?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: Search for a word in string and return everyhting before the searched word in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640330#M190705</link>
    <description>&lt;P&gt;I think that It s impossible to use SCAN here&lt;/P&gt;
&lt;P&gt;We cannot use a string like a delimiter with SCAN()&lt;/P&gt;
&lt;P&gt;and if we define "bank" like a delimiter, the case of "&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;"Shopping centre Mokotow" &lt;/SPAN&gt;" is not resolved.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data RawTbl;
infile cards dlmstr="bank" dlmsopt='i';
input string1 :$50. ;
cards;
HSBC buisness bank UK
Poland Bank Millenium
Shopping centre Mokotow
CommerzBank abc
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 16 Apr 2020 08:46:27 GMT</pubDate>
    <dc:creator>kelxxx</dc:creator>
    <dc:date>2020-04-16T08:46:27Z</dc:date>
    <item>
      <title>Search for a word in string and return everyhting before the searched word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640289#M190676</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a char column (string).&lt;/P&gt;
&lt;P&gt;I want to search for a word within the string.&lt;/P&gt;
&lt;P&gt;If the word exists in the field then I want to return all word(s) that before the searched word.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;Search word "bank"&lt;/P&gt;
&lt;P&gt;If the string value is "HSBC business bank UK"&amp;nbsp; &amp;nbsp;then will return "HSBC business"&lt;/P&gt;
&lt;P&gt;If the string value is "Poland Bank Millenium"&amp;nbsp; then will return "Poland"&lt;/P&gt;
&lt;P&gt;IF the string value is "Shopping centre Mokotow" then will return null value&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that it is better that the search will not be sensitive to capital/non capital letters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data RawTbl;
input string $50.
HSBC buisness bank UK
Poland Bank Millenium
Shopping centre Mokotow
;
Run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 07:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640289#M190676</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-04-16T07:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Search for a word in string and return everyhting before the searched word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640293#M190679</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an approach to achieve this, using pearl regular expressions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	length result $ 50;
	set rawtbl;
	result = prxchange('s/^(.*)\bbank\b.*$/$1/i',1,string);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-04-16 à 09.22.07.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38344iB3A75FE8A2EAE89A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2020-04-16 à 09.22.07.png" alt="Capture d’écran 2020-04-16 à 09.22.07.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 07:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640293#M190679</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-04-16T07:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Search for a word in string and return everyhting before the searched word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640295#M190681</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;PRE&gt;data have;
set rawtbl;
length x $45;
if index(upcase(string),"BANK")-2 gt 0 then 
x=substr(string,1,index(upcase(string),"BANK")-2);
run; &lt;/PRE&gt;&lt;P&gt;You can try it.&lt;/P&gt;&lt;P&gt;Have a nice day&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 07:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640295#M190681</guid>
      <dc:creator>kelxxx</dc:creator>
      <dc:date>2020-04-16T07:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Search for a word in string and return everyhting before the searched word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640301#M190685</link>
      <description>&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;However for string "Shopping centre Mokotow" I expect to get null value because word "Bank" is not found in this string.&lt;/P&gt;
&lt;P&gt;Can you also explain the code?&lt;/P&gt;
&lt;P&gt;Why do you write "bbank"&amp;nbsp; and not "bank"?&lt;/P&gt;
&lt;P&gt;What is the meaning of number "1"&amp;nbsp; in the code?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 07:37:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640301#M190685</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-04-16T07:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Search for a word in string and return everyhting before the searched word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640303#M190686</link>
      <description>&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;Can you please explain why you wrote number "2"&amp;nbsp; in your code?&lt;/P&gt;
&lt;P&gt;May you please explain the code please?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 07:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640303#M190686</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-04-16T07:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Search for a word in string and return everyhting before the searched word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640308#M190687</link>
      <description>&lt;P&gt;because "bank" is in middle and before bank is a blank " "&lt;/P&gt;
&lt;PRE&gt;1---5----10
abc bank&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #000000; font-family: arial,'Arial Unicode MS',geneva,'Lucida Grande',sans-serif; font-size: 100%; font-style: normal; font-variant: normal; font-weight: bold; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;index() function Searches a character expression for a string of characters, and returns the position of the string's first character for the first occurrence of the string.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;index() return the position of "b" of first occurrence of "bank" &amp;gt;&amp;gt;&amp;gt; 5&lt;/P&gt;
&lt;P&gt;but length of 'abc' is 3 &amp;gt;&amp;gt;&amp;gt; 5-2&lt;/P&gt;
&lt;P&gt;sorry, i m not good in English to explain&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 07:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640308#M190687</guid>
      <dc:creator>kelxxx</dc:creator>
      <dc:date>2020-04-16T07:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: Search for a word in string and return everyhting before the searched word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640309#M190688</link>
      <description>&lt;P&gt;It s not bbank , it is \b bank \b &amp;gt;&amp;gt;&amp;gt; \b … \b = boundary of word. the work here is "bank"&lt;/P&gt;
&lt;P&gt;you can view more detail of syntax in the link&amp;nbsp;&lt;A href="https://support.sas.com/rnd/base/datastep/perl_regexp/regexp-tip-sheet.pdf" target="_self"&gt;regexp-tip-sheet&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 07:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640309#M190688</guid>
      <dc:creator>kelxxx</dc:creator>
      <dc:date>2020-04-16T07:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Search for a word in string and return everyhting before the searched word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640315#M190693</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;: what would you expect if string is "Commerzbank"?&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235012"&gt;@kelxxx&lt;/a&gt; : i would replace index with findw and use "&amp;gt; 1" instead of "&amp;gt; 0" - if the string starts with &lt;EM&gt;bank&lt;/EM&gt; there is nothing on the left to be copied.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 08:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640315#M190693</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-04-16T08:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Search for a word in string and return everyhting before the searched word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640318#M190694</link>
      <description>&lt;P&gt;IF string is Commezbank then I expect to get Commerz in reult.&lt;/P&gt;
&lt;P&gt;Here is the code that is working fine.&lt;/P&gt;
&lt;P&gt;My question: Is it possible to use SCAN function in order to do the task?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data wanted;
set RawTbl;
Len=LENGTH(String);
Loc=INDEX(upcase(string),"BANK");
IF Lox&amp;gt;=2   then x=substr(String,1,Loc-1);
else x=' ';
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 08:15:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640318#M190694</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-04-16T08:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: Search for a word in string and return everyhting before the searched word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640330#M190705</link>
      <description>&lt;P&gt;I think that It s impossible to use SCAN here&lt;/P&gt;
&lt;P&gt;We cannot use a string like a delimiter with SCAN()&lt;/P&gt;
&lt;P&gt;and if we define "bank" like a delimiter, the case of "&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;"Shopping centre Mokotow" &lt;/SPAN&gt;" is not resolved.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data RawTbl;
infile cards dlmstr="bank" dlmsopt='i';
input string1 :$50. ;
cards;
HSBC buisness bank UK
Poland Bank Millenium
Shopping centre Mokotow
CommerzBank abc
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Apr 2020 08:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640330#M190705</guid>
      <dc:creator>kelxxx</dc:creator>
      <dc:date>2020-04-16T08:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: Search for a word in string and return everyhting before the searched word</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640449#M190772</link>
      <description>&lt;P&gt;sorry to revive the subject&lt;/P&gt;
&lt;P&gt;I found how to use SCAN() here&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data RawTbl;
input string $50. ;
cards;
HSBC buisness bank UK
Poland Bank Millenium
Shopping centre Mokotow
CommerzBank abc
;
Run;

data have;
set rawtbl;
string1=prxchange('s/bank/#/i',1,string);
if index(string1,"#") then result=scan(string1,1,"#");
run;
&lt;/PRE&gt;
&lt;P&gt;1. change the word "bank" to a specific character that cannot be exited in string&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;explain of prxchange('s/bank/#/i',1,string)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;s= to remplace&lt;/P&gt;
&lt;P&gt;/= separate the argument&lt;/P&gt;
&lt;P&gt;bank = key word&amp;nbsp; "bank"&lt;/P&gt;
&lt;P&gt;# = character to change&lt;/P&gt;
&lt;P&gt;i = case insensitive&lt;/P&gt;
&lt;P&gt;1 = replace the first occurrence of "bank"&amp;nbsp; (-1 if want to replace all "bank" in string)&lt;/P&gt;
&lt;P&gt;string= source of text;&lt;/P&gt;
&lt;P&gt;2. use SCAN() with delimiter = the character specified and IF for control then case of "&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; cursor: text; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;Shopping centre Mokotow&lt;/SPAN&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a good day.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Apr 2020 14:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-a-word-in-string-and-return-everyhting-before-the/m-p/640449#M190772</guid>
      <dc:creator>kelxxx</dc:creator>
      <dc:date>2020-04-16T14:15:14Z</dc:date>
    </item>
  </channel>
</rss>

