<?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: prxposn in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/prxposn/m-p/907371#M358180</link>
    <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Mon, 11 Dec 2023 19:14:32 GMT</pubDate>
    <dc:creator>edoyle1</dc:creator>
    <dc:date>2023-12-11T19:14:32Z</dc:date>
    <item>
      <title>prxposn</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxposn/m-p/907122#M358117</link>
      <description>&lt;P&gt;In the code below, I'm trying to get yr='2018'. Instead it is blank. What am I doing wrong? Using SAS 9.4.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data out;&lt;BR /&gt;retain prx_yr;&lt;BR /&gt;if _n_=1 then do;&lt;BR /&gt;prx_yr=prxparse('/20\d\d/');&lt;BR /&gt;end;&lt;BR /&gt;text='dir 2018 - Subject';&lt;BR /&gt;p=prxmatch(prx_yr,text);&lt;BR /&gt;if prxmatch(prx_yr,text) then yr=prxposn(prx_yr,1,text);&lt;BR /&gt;output;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 21:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxposn/m-p/907122#M358117</guid>
      <dc:creator>edoyle1</dc:creator>
      <dc:date>2023-12-08T21:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: prxposn</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxposn/m-p/907127#M358119</link>
      <description>&lt;P&gt;For such a simple search just use SUBSTR().&lt;/P&gt;
&lt;PRE&gt;228  data test;
229    input text $30.;
230    position=prxmatch('/20\d\d/',text);
231    if position then yr=substr(text,position,4);
232    put yr= text=;
233  cards;

yr=2018 text=dir 2018 - Subject
yr=  text=junk
&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Dec 2023 21:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxposn/m-p/907127#M358119</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-08T21:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: prxposn</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxposn/m-p/907141#M358121</link>
      <description>&lt;P&gt;The moment you enclose your expression into parentheses things will start to work.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1702087370398.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/91098iC76889BB84804865/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1702087370398.png" alt="Patrick_0-1702087370398.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1702086444833.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/91094i00616D9E8BA5A892/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1702086444833.png" alt="Patrick_0-1702086444833.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1702086485673.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/91095iB0C8E93B9E17E02E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1702086485673.png" alt="Patrick_1-1702086485673.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;With more recent SAS9 versions (forgot when that got introduced) you also don't need anymore to explicitly retain the variable that holds the pointer to the compiled RegEx and you don't need to wrap the prxparse() into a if _n_=1 ... condition. The compiler handles this now for you.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
  infile datalines truncover;
  input text $40.;
  datalines;
dir 2018 - Subject
dir 34 2018 - Subject
dir 9202099 2018 - Subject
;

data want;
  set have; 
  length yr $4;
  prx_yr=prxparse('/\b(20\d\d)\b/');
  if prxmatch(prx_yr,text) then yr=prxposn(prx_yr, 1, text);
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_2-1702086979768.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/91096i9F1E3613003E1D2A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_2-1702086979768.png" alt="Patrick_2-1702086979768.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;In above table prx_yr is always 1 which shows you that with above syntax the regex gets only compiled once. If it would get compiled for each row then the number (pointer to the compiled regex) would be different in each row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Dec 2023 10:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxposn/m-p/907141#M358121</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-12-09T10:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: prxposn</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prxposn/m-p/907371#M358180</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2023 19:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prxposn/m-p/907371#M358180</guid>
      <dc:creator>edoyle1</dc:creator>
      <dc:date>2023-12-11T19:14:32Z</dc:date>
    </item>
  </channel>
</rss>

