<?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 behaves strange in if condition in  data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-behaves-strange-in-if-condition-in-data-step/m-p/583170#M165986</link>
    <description>&lt;P&gt;You are using %put, which is a macro statement, and executed immediately when the code is compiled.&lt;/P&gt;
&lt;P&gt;As you can see in the log:&lt;/P&gt;
&lt;PRE&gt;29         DATA a;
30         a= prxmatch("/^TBDLZL\d{4}_[A-Z]/","&amp;amp;tablename");
31         IF prxmatch("/^TBDLZL\d{4}_[A-Z]/","&amp;amp;tablename") GT 0 THEN DO;
32         
33         %PUT "THE TABLE IS MATCHED OK";
"THE TABLE IS MATCHED OK"
34         
35         END;
36         ELSE DO;
37         %put ERROR: table name &amp;amp;tablename does not match;
ERROR: table name TBDLZL2223_AALLE_SDDS does not match
38         stop;
39         
40         END;
41         
42         RUN;
&lt;/PRE&gt;
&lt;P&gt;Both %put's are executed before the following statements are even read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the data ste statement put instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
a = prxmatch("/^TBDLZL\d{4}_[A-Z]/","&amp;amp;tablename"); 
if prxmatch("/^TBDLZL\d{4}_[A-Z]/","&amp;amp;tablename") gt 0
then put "THE TABLE IS MATCHED OK";
else put "ERROR: table name &amp;amp;tablename does not match";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 22 Aug 2019 13:21:29 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-08-22T13:21:29Z</dc:date>
    <item>
      <title>prxmatch behaves strange in if condition in  data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-behaves-strange-in-if-condition-in-data-step/m-p/583158#M165981</link>
      <description>&lt;P&gt;I have this MACRO variable that i get from a PROMPT in a SAS EG project.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to validate the string by using regex to match it,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im only creation dataset a for debugging, normally it would be _null_&lt;/P&gt;&lt;PRE&gt;DATA a;
a= prxmatch("/^TBDLZL\d{4}_[A-Z]/","&amp;amp;tablename"); 
IF prxmatch("/^TBDLZL\d{4}_[A-Z]/","&amp;amp;tablename") GT 0 THEN DO;

%PUT "THE TABLE IS MATCHED OK";

END;
ELSE DO;
%put ERROR: table name &amp;amp;tablename does not match;
stop; 

END;

RUN;&lt;/PRE&gt;&lt;P&gt;I behaves funny, the A variable in dataset a get the value 1 indicating that there is a match, but the conditionnel test dont get the same result, it test it to be zero&amp;nbsp;&lt;/P&gt;&lt;P&gt;the value of &amp;amp;tablename is&amp;nbsp;&amp;nbsp;TBDLZL2223_AALLE_SDDS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is it my condition that is wrong ?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 13:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-behaves-strange-in-if-condition-in-data-step/m-p/583158#M165981</guid>
      <dc:creator>havmaage</dc:creator>
      <dc:date>2019-08-22T13:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch behaves strange in if condition in  data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-behaves-strange-in-if-condition-in-data-step/m-p/583170#M165986</link>
      <description>&lt;P&gt;You are using %put, which is a macro statement, and executed immediately when the code is compiled.&lt;/P&gt;
&lt;P&gt;As you can see in the log:&lt;/P&gt;
&lt;PRE&gt;29         DATA a;
30         a= prxmatch("/^TBDLZL\d{4}_[A-Z]/","&amp;amp;tablename");
31         IF prxmatch("/^TBDLZL\d{4}_[A-Z]/","&amp;amp;tablename") GT 0 THEN DO;
32         
33         %PUT "THE TABLE IS MATCHED OK";
"THE TABLE IS MATCHED OK"
34         
35         END;
36         ELSE DO;
37         %put ERROR: table name &amp;amp;tablename does not match;
ERROR: table name TBDLZL2223_AALLE_SDDS does not match
38         stop;
39         
40         END;
41         
42         RUN;
&lt;/PRE&gt;
&lt;P&gt;Both %put's are executed before the following statements are even read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the data ste statement put instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
a = prxmatch("/^TBDLZL\d{4}_[A-Z]/","&amp;amp;tablename"); 
if prxmatch("/^TBDLZL\d{4}_[A-Z]/","&amp;amp;tablename") gt 0
then put "THE TABLE IS MATCHED OK";
else put "ERROR: table name &amp;amp;tablename does not match";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Aug 2019 13:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-behaves-strange-in-if-condition-in-data-step/m-p/583170#M165986</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-22T13:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch behaves strange in if condition in  data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-behaves-strange-in-if-condition-in-data-step/m-p/583171#M165987</link>
      <description>&lt;P&gt;I made a small correction to you RegEX, which I think is necessary&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a= prxmatch("/^tbdlzl\d{4}_[a-z_]*/","&amp;amp;tablename"); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, use the Data Step Put Statement instead of the Macro %Put&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 13:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-behaves-strange-in-if-condition-in-data-step/m-p/583171#M165987</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-22T13:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: prxmatch behaves strange in if condition in  data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxmatch-behaves-strange-in-if-condition-in-data-step/m-p/583180#M165994</link>
      <description>Thanks, yes your right this match better</description>
      <pubDate>Thu, 22 Aug 2019 13:49:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxmatch-behaves-strange-in-if-condition-in-data-step/m-p/583180#M165994</guid>
      <dc:creator>havmaage</dc:creator>
      <dc:date>2019-08-22T13:49:43Z</dc:date>
    </item>
  </channel>
</rss>

