<?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: prxmatch('/\b . . . in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/694961#M212001</link>
    <description>&lt;P&gt;&lt;EM&gt;"&lt;/EM&gt;&lt;SPAN&gt;&lt;EM&gt;I am still having trouble understanding the specifics of the /\b . . . \b/ notation."&lt;/EM&gt;-&amp;nbsp; This is Regex metacharacter used to encapsulate a string to make that a word , rather than a string. If you are new to ReGeX, it's a bit of a learning curve. For example,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Look at the 7th record in the result of the below test and compare with 1st or 3rd one-&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
 input charge $20.;
 cards;
 bjbj PSP
 P.S.P
 dbsfjbwe PSP h
 v dhw P.S.P
 P.S.P. BJHB
 huhbk
 PSPppppppp
;
data want;
 set have;
 psp=(prxmatch('/\bPSP\b/',charge) | index(charge,'P.S.P.'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;"Since index and prxmatch return a position in the string?"- Yes, however that's the definition&amp;nbsp;of those functions though when used in an "boolean expression that uses AND/OR/NOT" the result of the expression is what is assigned to the assignment variable on the left hand side.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My apologies if I am not explaining well enough. I am useless when it comes to this.&amp;nbsp; Requesting&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;/&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; or Mr Kolmogorov&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; their time for a more neat explanation. Thank you gentlemen in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Oct 2020 17:40:11 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-10-28T17:40:11Z</dc:date>
    <item>
      <title>prxmatch('/\b . . .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/694942#M211994</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am currently working my way through someone else's code and have come across lines that identify whether a given string is present in two different ways:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;psp=(prxmatch('/\bPSP\b/',charge)&amp;gt;0 | index(charge,'P.S.P.')&amp;gt;0);
punsh=(index(charge,"PUNISH")&amp;gt;0);&lt;/PRE&gt;
&lt;P&gt;The use of index makes sense to me, but I am not sure what is going with prxmatch--particularly the slashes and the uses of 'b.' Can someone shed some light on this?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 16:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/694942#M211994</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-10-28T16:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch('/\b . . .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/694946#M211995</link>
      <description>&lt;PRE&gt;psp=(prxmatch('/\bPSP\b/',charge)&amp;gt;0 | index(charge,'P.S.P.')&amp;gt;0);&lt;/PRE&gt;
&lt;P&gt;is a boolean expression resulting&amp;nbsp; in values 0 or 1.&amp;nbsp; The pipe | is the OR operator. Therefore there are 2 different expressions. If the &lt;STRONG&gt;word PSP(&lt;/STRONG&gt;&lt;EM&gt;\b escape metacharacter for word search&lt;/EM&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&amp;nbsp;is found in &lt;STRONG&gt;charge , it's true.&amp;nbsp;&lt;/STRONG&gt;If the string P.S.P is found in variable charge, it is again true. Basically the dual expression is evaluated to true with 1's and false with 0's. If at least one is true, it is true aka 1. HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, &lt;STRONG&gt;&amp;gt;0&lt;/STRONG&gt; is not really required in a boolean expression with an &lt;STRONG&gt;OR&lt;/STRONG&gt; operator for the reason True/False evaluation would anyway result in 1 or 0 even if the position of the string or word occurs anywhere beyond position 1. Therefore,-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;psp=(prxmatch('/\bPSP\b/',charge) | index(charge,'P.S.P.'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will suffice. However, for reading ease, it's probably good to have &amp;gt;0.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 17:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/694946#M211995</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-10-28T17:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch('/\b . . .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/694953#M211998</link>
      <description>&lt;P&gt;Thanks for the reply. I am still having trouble understanding the specifics of the /\b . . . \b/ notation. Also, a 0 or 1 is not necessarily returned, though, right? Since index and prxmatch return a position in the string?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 17:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/694953#M211998</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-10-28T17:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch('/\b . . .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/694961#M212001</link>
      <description>&lt;P&gt;&lt;EM&gt;"&lt;/EM&gt;&lt;SPAN&gt;&lt;EM&gt;I am still having trouble understanding the specifics of the /\b . . . \b/ notation."&lt;/EM&gt;-&amp;nbsp; This is Regex metacharacter used to encapsulate a string to make that a word , rather than a string. If you are new to ReGeX, it's a bit of a learning curve. For example,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Look at the 7th record in the result of the below test and compare with 1st or 3rd one-&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
 input charge $20.;
 cards;
 bjbj PSP
 P.S.P
 dbsfjbwe PSP h
 v dhw P.S.P
 P.S.P. BJHB
 huhbk
 PSPppppppp
;
data want;
 set have;
 psp=(prxmatch('/\bPSP\b/',charge) | index(charge,'P.S.P.'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;"Since index and prxmatch return a position in the string?"- Yes, however that's the definition&amp;nbsp;of those functions though when used in an "boolean expression that uses AND/OR/NOT" the result of the expression is what is assigned to the assignment variable on the left hand side.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My apologies if I am not explaining well enough. I am useless when it comes to this.&amp;nbsp; Requesting&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;/&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; or Mr Kolmogorov&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; their time for a more neat explanation. Thank you gentlemen in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 17:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/694961#M212001</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-10-28T17:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch('/\b . . .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/695003#M212009</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326526"&gt;@raivester&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;has already mentioned, the "&lt;FONT face="courier new,courier"&gt;\b&lt;/FONT&gt;" is a &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0s9ilagexmjl8n1u7e1t1jfnzlk.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;PRX metacharacter&lt;/A&gt; and represents a "word boundary," i.e., unlike &lt;FONT face="courier new,courier"&gt;index(charge,'PSP')&lt;/FONT&gt; the PRXMATCH criterion would not be satisfied if variable &lt;FONT face="courier new,courier"&gt;charge&lt;/FONT&gt; contained text like "&lt;FONT face="courier new,courier"&gt;TOPSPIN&lt;/FONT&gt;." A naive suggestion to find "&lt;FONT face="courier new,courier"&gt;PSP&lt;/FONT&gt;" &lt;EM&gt;only as a word&lt;/EM&gt; may be to use&amp;nbsp;&lt;FONT face="courier new,courier"&gt;index(charge,' PSP ')&lt;/FONT&gt;. But this would fail in various circumstances, e.g., for texts in variable &lt;FONT face="courier new,courier"&gt;charge&lt;/FONT&gt; like&lt;/P&gt;
&lt;PRE&gt;PSP
The Party of SAS Programmers (PSP) won the election.
The majority voted for the PSP.&lt;/PRE&gt;
&lt;P&gt;However, for more specialized tools such as the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p16rdsa30vmm43n1ej4936nwa01t.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;FINDW function&lt;/A&gt; or PRXMATCH using the "&lt;FONT face="courier new,courier"&gt;\b&lt;/FONT&gt;" metacharacter these (and similar) examples are no problem because they recognize the beginning and the end of a string, parentheses and punctuation marks as word delimiters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A Boolean expression equals 1 for TRUE and 0 for FALSE, e.g., if it is assigned to a numeric variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not in your code, but in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;'s simplified expression another fact comes into play: Numeric values can be used as Boolean expressions and are evaluated as FALSE (i.e. 0) if they are 0 or missing. In all other cases (i.e., positive or negative numbers) they are evaluated as TRUE (i.e. 1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another example (SAS log):&lt;/P&gt;
&lt;PRE&gt;402  data _null_;
403  if (4 | 0) = 1 and (4 &amp;amp; 5) = 1 and (. &amp;amp; 5) = 0 then put 'OK';
404  run;

OK
&lt;/PRE&gt;
&lt;P&gt;Note, however, that a single numeric expression would not be interpreted as a Boolean expression: In your second example (&lt;FONT face="courier new,courier"&gt;punsh=...&lt;/FONT&gt;) the "&lt;FONT face="courier new,courier"&gt;&amp;gt;0&lt;/FONT&gt;" cannot be removed (in general) without changing the values assigned to &lt;FONT face="courier new,courier"&gt;punsh&lt;/FONT&gt;. Without the "&lt;FONT face="courier new,courier"&gt;&amp;gt;0&lt;/FONT&gt;", values (character positions) &amp;gt;1 would be possible.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 19:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/695003#M212009</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-10-28T19:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch('/\b . . .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/695028#M212023</link>
      <description>&lt;P&gt;For such simple regular expression, and if maintenance is an issue (as seems to be the case), you can probably use the FINDW function with similar results.&lt;/P&gt;
&lt;P&gt;\b identifies a word boundary, just like FINDW looks for word delimiters. If your program is old enough, maybe FINDW was unavailable when it was written.&lt;/P&gt;
&lt;P&gt;So in your case, they are probably interchangeable, and would make you more comfortable using that code.&lt;/P&gt;
&lt;P&gt;An alternative is that you use the opportunity to familiarise yourself with regular expressions. They look ugly but are invaluable useful when manipulating text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 20:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-b/m-p/695028#M212023</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-10-28T20:33:46Z</dc:date>
    </item>
  </channel>
</rss>

