<?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: can i scan a word by other string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/can-i-scan-a-word-by-other-string/m-p/630821#M186797</link>
    <description>You're welcome &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/107435"&gt;@harrylui&lt;/a&gt;!</description>
    <pubDate>Tue, 10 Mar 2020 08:43:59 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-03-10T08:43:59Z</dc:date>
    <item>
      <title>can i scan a word by other string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-i-scan-a-word-by-other-string/m-p/630595#M186687</link>
      <description>&lt;P&gt;Good Day,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can i scan a word by other string?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;string1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string2&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ALIPAYHKCUBER COMPANY HKG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;ALIPAYHKCUBERCOMPANY&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;the result i want is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;ALIPAYHKCUBER COMPANY&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and also , can i develop a program that can extract string before blank&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for this example, i want to drop all the character after two blank&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ALIPAYHKCUBER COMPANY HKG&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks in advance&lt;/P&gt;
&lt;P&gt;Harry&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 08:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-i-scan-a-word-by-other-string/m-p/630595#M186687</guid>
      <dc:creator>harrylui</dc:creator>
      <dc:date>2020-03-09T08:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: can i scan a word by other string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-i-scan-a-word-by-other-string/m-p/630602#M186692</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/107435"&gt;@harrylui&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a way to achieve this, using pearl regular expressions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines dlm="," truncover;
	input string1:$50.;
	datalines;
	ALIPAYHKCUBER COMPANY HKG
;
run;

data want;
	set have;
	length string2 string3 $ 100;
	/* string2: look for ALIPAYHKCUBER COMPANY and retrieve this word */
	if prxmatch('/\bALIPAYHKCUBER COMPANY\b/', string1) then 
		string2 = prxchange('s/^.*(\bALIPAYHKCUBER COMPANY\b).*$/$1/',-1, string1);
	/* string3: drop all the character after two blank */
	if prxmatch('/[^\s]*\s[^\s]*/', string1) then 
		string3 = prxchange('s/^(\s*[^\s]*\s[^\s]*)\s.*$/$1/',-1, string1);
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;Explanations:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;string2
&lt;UL&gt;
&lt;LI&gt;if SAS finds the pattern &lt;FONT color="#FF00FF"&gt;\bALIPAYHKCUBER COMPANY\b&lt;/FONT&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;(NB: \b = match a word boundary) using the prxmatch function, then it retrieves this word using the prxchange function. In practice, it looks for the whole pattern ^.*&lt;FONT color="#FF00FF"&gt;(\bALIPAYHKCUBER COMPANY\b)&lt;/FONT&gt;.*$&amp;nbsp;and it replace it by the group in parenthesis &lt;FONT color="#FF00FF"&gt;$1&lt;/FONT&gt;&lt;BR /&gt;
&lt;UL&gt;
&lt;LI&gt;\s = looks for a blank&lt;/LI&gt;
&lt;LI&gt;. = looks for any character&lt;/LI&gt;
&lt;LI&gt;* = looks for the specified character before the *&amp;nbsp;0, 1 or more times&lt;/LI&gt;
&lt;LI&gt;^ = matches the beginning of the string&lt;/LI&gt;
&lt;LI&gt;$ = matches the end of the string&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;string3
&lt;UL&gt;
&lt;LI&gt;if SAS finds the pattern &lt;FONT color="#3366FF"&gt;[^\s]*\s[^\s]*&lt;/FONT&gt;&amp;nbsp;using the prxmatch function, then it retrieves this pattern using the prxchange function. In practice, it looks for the whole pattern ^&lt;FONT color="#3366FF"&gt;(\s*[^\s]*\s[^\s]*)&lt;/FONT&gt;\s.*$&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;and it replace it by the group in parenthesis &lt;FONT color="#3366FF"&gt;$1&lt;/FONT&gt;
&lt;UL&gt;
&lt;LI&gt;\s = looks for a blank&lt;/LI&gt;
&lt;LI&gt;. = looks for any character&lt;/LI&gt;
&lt;LI&gt;&lt;CODE class=" language-sas"&gt;[^\s]&lt;/CODE&gt;&amp;nbsp;= looks for any character except a blank&lt;/LI&gt;
&lt;LI&gt;* = looks for the specified character before the * 0, 1 or more times&lt;/LI&gt;
&lt;LI&gt;^ = matches the beginning of the string&lt;/LI&gt;
&lt;LI&gt;$ = matches the end of the string&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;NB, if you use the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	if find(string1,"ALIPAYHKCUBER COMPANY") then string2 = "ALIPAYHKCUBER COMPANY";
	string3 = catx(" ", scan(string1,1," "), scan(string1,2," "));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;- the calculation of string3 is strictly equivalent to the above method using pearl regular expression.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;- the calculation of string2 differs:&lt;/STRONG&gt;&lt;/FONT&gt; in fact, it looks for the string "ALIPAYHKCUBER COMPANY", but really as a string and not as two words. For example, xxxALIPAYHKCUBER COMPANY would be retrieved with this code using the FIND function. It would not be retrieved by the PRXMATCH function, as it looks also for a word boundary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best,&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 10:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-i-scan-a-word-by-other-string/m-p/630602#M186692</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-09T10:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: can i scan a word by other string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-i-scan-a-word-by-other-string/m-p/630686#M186732</link>
      <description>&lt;P&gt;Not quite sure if this is what you want, but:&lt;/P&gt;
&lt;P&gt;Given string1="&lt;SPAN&gt;ALIPAYHKCUBER COMPANY HKG" and string2="ALIPAYHKCUBERCOMPANY", you can try this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
  set have;
  string1=catx(' ',scan(string1,1,' '),scan(string1,2,' '));
  check=string2=compress(string1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;STRING1 should then contain the first 2 words of the original string, and the variable CHECK is 1 if STRING2 matches that, otherwise 0.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 17:29:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-i-scan-a-word-by-other-string/m-p/630686#M186732</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-03-09T17:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: can i scan a word by other string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-i-scan-a-word-by-other-string/m-p/630816#M186793</link>
      <description>&lt;P&gt;THANK YOU!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 08:37:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-i-scan-a-word-by-other-string/m-p/630816#M186793</guid>
      <dc:creator>harrylui</dc:creator>
      <dc:date>2020-03-10T08:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: can i scan a word by other string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/can-i-scan-a-word-by-other-string/m-p/630821#M186797</link>
      <description>You're welcome &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/107435"&gt;@harrylui&lt;/a&gt;!</description>
      <pubDate>Tue, 10 Mar 2020 08:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/can-i-scan-a-word-by-other-string/m-p/630821#M186797</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-10T08:43:59Z</dc:date>
    </item>
  </channel>
</rss>

