<?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 function for values with decimal point and without in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/954864#M372936</link>
    <description>Thank you, Quickbluefish!</description>
    <pubDate>Wed, 01 Jan 2025 18:27:00 GMT</pubDate>
    <dc:creator>SASdevAnneMarie</dc:creator>
    <dc:date>2025-01-01T18:27:00Z</dc:date>
    <item>
      <title>Prxmatch function for values with decimal point and without</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/954855#M372928</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I apply this function to get 1.50% or 1,50% :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if prxmatch("/\b1,5|\b1\.5/",lb_lg)&amp;gt;0 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But when I apply :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;if prxmatch("/\b1/",lb_lg)&amp;gt;0 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to get just 1% I have also 1,50%, 1.50% and 1%.&lt;/P&gt;
&lt;P&gt;Which function do I need to apply to get only the data with 1% ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help !&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2025 14:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/954855#M372928</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2025-01-01T14:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: Prxmatch function for values with decimal point and without</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/954857#M372930</link>
      <description>&lt;P&gt;It depends what you expect to come after the "1" in 1%. Do you expect it to read "1.0"? "1.0%", "1%", "1 %"?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Right now, all you're specifying in the 2nd prxmatch is that there's a "1" at the beginning of a word boundary, so that includes " 1", " 1.5", etc.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;You could try, for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards dsd truncover dlm=',';
length x $20;
input x;
cards;
this is 1.5%
this is 1 %
this is 1.0%
this is 1%
this is 2%
;
run;

data test;
set test;
length is_1pct 3;
is_1pct=0;
if prxmatch("/\b1(\.0\b|\.0\%|\%|\s)/",x)&amp;gt;0 then is_1pct=1;
run;

proc print data=test; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;...but I would definitely do some testing - others here definitely know regex better than me.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2025 14:37:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/954857#M372930</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-01-01T14:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Prxmatch function for values with decimal point and without</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/954859#M372932</link>
      <description>&lt;P&gt;Thanks for the sample, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223320"&gt;@quickbluefish&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a reason we need to use regex? I use regexes a lot, but I always forget how to use them until I need them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards dsd truncover dlm=',';
length x $20;
input x;
cards;
this is 1.5%
this is 1 %
this is 1.0%
this is 1%
this is 2%
this is 400   %
1.2% is wow
;
run;

data want;
	set test;
	/* Removing spaces */
	var = compress(x, , "kdp");
	/* keeping spaces but loses repeated spaces */
	var2 = compress(x, , "kdps");
run;

proc print; run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;COMPRESS can do it, but it obviously starts to lose unique patterns. Can a string have multiple percentages? Does it have to have a percent sign to extract it? It's tough to get the right answer given all the possible scenarios.&lt;/P&gt;
&lt;PRE&gt;x 	var 	var2
this is 1.5% 	1.5% 	1.5%
this is 1 % 	1% 	1 %
this is 1.0% 	1.0% 	1.0%
this is 1% 	1% 	1%
this is 2% 	2% 	2%
this is 400 % 	400% 	400 %
1.2% is wow 	1.2% 	1.2%&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2025 17:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/954859#M372932</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2025-01-01T17:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Prxmatch function for values with decimal point and without</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/954861#M372934</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281770"&gt;@maguiremq&lt;/a&gt;&amp;nbsp;- yes, almost certainly could be done without regex, though the more complex / messy it gets, the more difficult it's going to be without it.&amp;nbsp; I don't use regex enough to use it fluently or in any of the really sophisticated ways, and frankly, if I need to do something complicated with regex, I'm more likely to use Python than SAS.&amp;nbsp; One thing about regex is that it's a very good use case for LLMs like ChatGPT - both for generating syntax or explaining / troubleshooting syntax that you already have.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this case, your compress approach seems good - I never really remember the various flags that go in the 3rd argument.&amp;nbsp; Overall, though, we'd really need to see the full scope of possible ways these percentages could appear in the data in order to give a complete answer.&amp;nbsp; Thanks for your response!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2025 17:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/954861#M372934</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-01-01T17:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Prxmatch function for values with decimal point and without</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/954864#M372936</link>
      <description>Thank you, Quickbluefish!</description>
      <pubDate>Wed, 01 Jan 2025 18:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/954864#M372936</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2025-01-01T18:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Prxmatch function for values with decimal point and without</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/955011#M372983</link>
      <description>Apologies &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223320"&gt;@quickbluefish&lt;/a&gt; - I wasn't questioning you. I was just asking general questions about the programming situation and accidentally replied to yours!</description>
      <pubDate>Fri, 03 Jan 2025 13:39:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Prxmatch-function-for-values-with-decimal-point-and-without/m-p/955011#M372983</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2025-01-03T13:39:00Z</dc:date>
    </item>
  </channel>
</rss>

