<?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: SAS regular expressions: combination of ^ and $ not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-regular-expressions-combination-of-and-not-working/m-p/872860#M344856</link>
    <description>&lt;P&gt;SAS only has fixed length character variables.&lt;/P&gt;
&lt;P&gt;So your test find find 3 digits will not work since instead of three digits you have 3 digits followed by 5 spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be able to just add a TRIM() function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if prxmatch('/^[0-9]{3}$/',trim(var2));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 Apr 2023 15:59:58 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-04-28T15:59:58Z</dc:date>
    <item>
      <title>SAS regular expressions: combination of ^ and $ not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-regular-expressions-combination-of-and-not-working/m-p/872856#M344854</link>
      <description>&lt;P&gt;Hi All!&lt;/P&gt;
&lt;P&gt;I am very new to regex - I am currently busy with an introductory course. But I have a problem where the regex works when I use it in a grep command, but when I translate it into SAS it doesn't work. Please don't leaugh at the very basic example lol, I have attached the input file and here is my code (extracting all lines that contains exactly 3 digits):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Grep command (returns the correct 3 lines):&lt;/P&gt;
&lt;P&gt;grep -E '^[0-9]{3}$' regex18.txt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS code (returns 0 rows):&lt;/P&gt;
&lt;P&gt;proc import file='/sas/batch/sasdata/users/heididt/regex/ExerciseInputFiles/regex18.txt' out=example replace;&lt;BR /&gt;getnames=NO;datarow=1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data example;&lt;BR /&gt;length var2 $8.;&lt;BR /&gt;set example;&lt;BR /&gt;var2=left(put(var1,8.));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data example_out;&lt;BR /&gt;set example;&lt;BR /&gt;if prxmatch('/^[0-9]{3}$/',var2);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 15:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-regular-expressions-combination-of-and-not-working/m-p/872856#M344854</guid>
      <dc:creator>HeidiDT</dc:creator>
      <dc:date>2023-04-28T15:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS regular expressions: combination of ^ and $ not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-regular-expressions-combination-of-and-not-working/m-p/872860#M344856</link>
      <description>&lt;P&gt;SAS only has fixed length character variables.&lt;/P&gt;
&lt;P&gt;So your test find find 3 digits will not work since instead of three digits you have 3 digits followed by 5 spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be able to just add a TRIM() function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if prxmatch('/^[0-9]{3}$/',trim(var2));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2023 15:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-regular-expressions-combination-of-and-not-working/m-p/872860#M344856</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T15:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS regular expressions: combination of ^ and $ not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-regular-expressions-combination-of-and-not-working/m-p/872862#M344857</link>
      <description>&lt;P&gt;EXCELLENT - thanks so much!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 16:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-regular-expressions-combination-of-and-not-working/m-p/872862#M344857</guid>
      <dc:creator>HeidiDT</dc:creator>
      <dc:date>2023-04-28T16:11:38Z</dc:date>
    </item>
  </channel>
</rss>

