<?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 How do I apply regular expression patterns from a file? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-regular-expression-patterns-from-a-file/m-p/491002#M128647</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets:&lt;/P&gt;&lt;P&gt;* have1, a list of non-standardized codes&lt;/P&gt;&lt;P&gt;* have2, a list of regular expressions and a standardized code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each record in have1, I want to search for a regular expression in have2 that matches the code. If there is a matching regular expression, I want to put the value of the standardized code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code below achieves the desired output, but it has the patterns hard coded. In other word, it doesnt use have2 at all. I want to change the code in the last data step so the patterns are read from have2. In this manner, the pattern list can be dynamic as have2 changes.&amp;nbsp;The same code is also attached.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know if this can be achieved?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA have1;&lt;BR /&gt;INPUT&lt;BR /&gt;code : $CHAR255. ;&lt;BR /&gt;DATALINES4;&lt;BR /&gt;Acreditacion por rechazo de transferencia&lt;BR /&gt;Acreditacion por rechazo de transferencia (cuenta cerrada)&lt;BR /&gt;Ajuste por error de acreditacion. De 4743 a 21606&lt;BR /&gt;Ajuste por error de Imputaci¢n (Rc Nø89162)&lt;BR /&gt;ARPY020700006&lt;BR /&gt;ARPY220300023&lt;BR /&gt;ARPY230800024&lt;BR /&gt;ARPY240800031&lt;BR /&gt;;;;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA have2;&lt;BR /&gt;INFILE DATALINES4&lt;BR /&gt;DLM='09'X&lt;BR /&gt;MISSOVER&lt;BR /&gt;DSD ;&lt;BR /&gt;INPUT&lt;BR /&gt;regexp_id : BEST32.&lt;BR /&gt;regexp : $CHAR255.&lt;BR /&gt;replacement : $CHAR255. ;&lt;BR /&gt;DATALINES4;&lt;BR /&gt;1 /acreditacion/ Acreditación por rechazo transferencia&lt;BR /&gt;2 /^ajuste[\w\s]/ Ajuste por error de acreditación entre cuentas&lt;BR /&gt;3 /py\d{9}/ Ingreso CPD&lt;BR /&gt;4 /comision*SGR$/ Comisión de terceros - SGR&lt;BR /&gt;;;;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have1;&lt;BR /&gt;IF _N_ = 1 THEN DO;&lt;BR /&gt;patt1 = prxparse ("/acreditacion/");&lt;BR /&gt;patt2 = prxparse ("/^ajuste[\w\s]/");&lt;BR /&gt;patt3 = prxparse ("/py\d{9}/");&lt;BR /&gt;patt4 = prxparse ("/comision*SGR$/");&lt;BR /&gt;END;&lt;BR /&gt;RETAIN patt1-patt4;&lt;BR /&gt;code = strip(lowcase(code));&lt;BR /&gt;IF ( prxmatch(patt1, code) &amp;gt; 0) THEN std_code = "Acreditación por rechazo transferencia";&lt;BR /&gt;IF ( prxmatch(patt2, code) &amp;gt; 0) THEN std_code = "Ajuste por error de acreditación";&lt;BR /&gt;IF ( prxmatch(patt3, code) &amp;gt; 0) THEN std_code = "Ingreso CPD";&lt;BR /&gt;IF ( prxmatch(patt4, code) &amp;gt; 0) THEN std_code = "Comisión de terceros - SGR";&lt;BR /&gt;DROP patt1-patt4;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Aug 2018 21:20:17 GMT</pubDate>
    <dc:creator>HGimenez</dc:creator>
    <dc:date>2018-08-29T21:20:17Z</dc:date>
    <item>
      <title>How do I apply regular expression patterns from a file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-regular-expression-patterns-from-a-file/m-p/491002#M128647</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets:&lt;/P&gt;&lt;P&gt;* have1, a list of non-standardized codes&lt;/P&gt;&lt;P&gt;* have2, a list of regular expressions and a standardized code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each record in have1, I want to search for a regular expression in have2 that matches the code. If there is a matching regular expression, I want to put the value of the standardized code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code below achieves the desired output, but it has the patterns hard coded. In other word, it doesnt use have2 at all. I want to change the code in the last data step so the patterns are read from have2. In this manner, the pattern list can be dynamic as have2 changes.&amp;nbsp;The same code is also attached.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know if this can be achieved?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA have1;&lt;BR /&gt;INPUT&lt;BR /&gt;code : $CHAR255. ;&lt;BR /&gt;DATALINES4;&lt;BR /&gt;Acreditacion por rechazo de transferencia&lt;BR /&gt;Acreditacion por rechazo de transferencia (cuenta cerrada)&lt;BR /&gt;Ajuste por error de acreditacion. De 4743 a 21606&lt;BR /&gt;Ajuste por error de Imputaci¢n (Rc Nø89162)&lt;BR /&gt;ARPY020700006&lt;BR /&gt;ARPY220300023&lt;BR /&gt;ARPY230800024&lt;BR /&gt;ARPY240800031&lt;BR /&gt;;;;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA have2;&lt;BR /&gt;INFILE DATALINES4&lt;BR /&gt;DLM='09'X&lt;BR /&gt;MISSOVER&lt;BR /&gt;DSD ;&lt;BR /&gt;INPUT&lt;BR /&gt;regexp_id : BEST32.&lt;BR /&gt;regexp : $CHAR255.&lt;BR /&gt;replacement : $CHAR255. ;&lt;BR /&gt;DATALINES4;&lt;BR /&gt;1 /acreditacion/ Acreditación por rechazo transferencia&lt;BR /&gt;2 /^ajuste[\w\s]/ Ajuste por error de acreditación entre cuentas&lt;BR /&gt;3 /py\d{9}/ Ingreso CPD&lt;BR /&gt;4 /comision*SGR$/ Comisión de terceros - SGR&lt;BR /&gt;;;;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have1;&lt;BR /&gt;IF _N_ = 1 THEN DO;&lt;BR /&gt;patt1 = prxparse ("/acreditacion/");&lt;BR /&gt;patt2 = prxparse ("/^ajuste[\w\s]/");&lt;BR /&gt;patt3 = prxparse ("/py\d{9}/");&lt;BR /&gt;patt4 = prxparse ("/comision*SGR$/");&lt;BR /&gt;END;&lt;BR /&gt;RETAIN patt1-patt4;&lt;BR /&gt;code = strip(lowcase(code));&lt;BR /&gt;IF ( prxmatch(patt1, code) &amp;gt; 0) THEN std_code = "Acreditación por rechazo transferencia";&lt;BR /&gt;IF ( prxmatch(patt2, code) &amp;gt; 0) THEN std_code = "Ajuste por error de acreditación";&lt;BR /&gt;IF ( prxmatch(patt3, code) &amp;gt; 0) THEN std_code = "Ingreso CPD";&lt;BR /&gt;IF ( prxmatch(patt4, code) &amp;gt; 0) THEN std_code = "Comisión de terceros - SGR";&lt;BR /&gt;DROP patt1-patt4;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 21:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-regular-expression-patterns-from-a-file/m-p/491002#M128647</guid>
      <dc:creator>HGimenez</dc:creator>
      <dc:date>2018-08-29T21:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply regular expression patterns from a file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-regular-expression-patterns-from-a-file/m-p/491016#M128651</link>
      <description>&lt;P&gt;1. The data -generation code you provided does not work.&lt;/P&gt;
&lt;P&gt;I fixed it. Please try to provide working code, and test it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. I made the regular expressions case insensitive to get&amp;nbsp;good matches. Change as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE1;
  input CODE &amp;amp; $char255. ;
datalines4;
Acreditacion por rechazo de transferencia
Acreditacion por rechazo de transferencia (cuenta cerrada)
Ajuste por error de acreditacion. De 4743 a 21606
Ajuste por error de Imputaci¢n (Rc Nø89162)
ARPY020700006
ARPY220300023
ARPY230800024
ARPY240800031
;;;;
run;

data HAVE2;
input REGEXP_ID  
      REGEXP      : $char255.
      REPLACEMENT &amp;amp; $char255. ;
datalines4;
1 /acreditacion/i Acreditación por rechazo transferencia
2 /^ajuste[\w\s]/i Ajuste por error de acreditación entre cuentas
3 /py\d{9}/ Ingreso CPD
4 /comision*SGR$/ Comisión de terceros - SGR
;;;;
run;

proc sql;
  select * 
  from HAVE1, HAVE2
  where prxmatch(REGEXP,CODE);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col"&gt;CODE&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;REGEXP_ID&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;REGEXP&lt;/TH&gt;
&lt;TH class="l b header" scope="col"&gt;REPLACEMENT&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Acreditacion por rechazo de transferencia&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;/acreditacion/i&lt;/TD&gt;
&lt;TD class="l data"&gt;Acreditación por rechazo transferencia&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Acreditacion por rechazo de transferencia (cuenta cerrada)&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;/acreditacion/i&lt;/TD&gt;
&lt;TD class="l data"&gt;Acreditación por rechazo transferencia&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Ajuste por error de acreditacion. De 4743 a 21606&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;/acreditacion/i&lt;/TD&gt;
&lt;TD class="l data"&gt;Acreditación por rechazo transferencia&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Ajuste por error de acreditacion. De 4743 a 21606&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;/^ajuste[\w\s]/i&lt;/TD&gt;
&lt;TD class="l data"&gt;Ajuste por error de acreditación entre cuentas&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Ajuste por error de Imputaci¢n (Rc Nø89162)&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;/^ajuste[\w\s]/i&lt;/TD&gt;
&lt;TD class="l data"&gt;Ajuste por error de acreditación entre cuentas&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 22:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-regular-expression-patterns-from-a-file/m-p/491016#M128651</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-29T22:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I apply regular expression patterns from a file?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-regular-expression-patterns-from-a-file/m-p/491044#M128670</link>
      <description>Excellent !! Thanks *a lot* ChrisNZ !!&lt;BR /&gt;</description>
      <pubDate>Thu, 30 Aug 2018 01:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-apply-regular-expression-patterns-from-a-file/m-p/491044#M128670</guid>
      <dc:creator>HGimenez</dc:creator>
      <dc:date>2018-08-30T01:02:31Z</dc:date>
    </item>
  </channel>
</rss>

