<?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: Macro parameter  as a search string in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960729#M43161</link>
    <description>regex 8 is defined as numeric&lt;BR /&gt;because prxparse(pattern); return pattern id&lt;BR /&gt;NOTE: Numeric values have been converted to character&lt;BR /&gt;values at the places given by: (Line):(Column).&lt;BR /&gt;7:11 this is because file path contains numbers</description>
    <pubDate>Mon, 03 Mar 2025 15:09:56 GMT</pubDate>
    <dc:creator>Dimax</dc:creator>
    <dc:date>2025-03-03T15:09:56Z</dc:date>
    <item>
      <title>Macro parameter  as a search string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960720#M43159</link>
      <description>&lt;P&gt;Hello, I am learning SAS and trying to write a macro program that takes a file path as a macro parameter and a second parameter for the search term to be found in this file. However, I can't get it to work because I am getting the Error&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;ERROR: The regular expression passed to the function PRXMATCH contains a syntax error.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;SPAN&gt;This is the code&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro matcher_prxmatch(path, search);
data prxmatch;
length pos count zeilen_nr 8 line $32767 regex pattern $100 lrecl 8 search $100;
infile "&amp;amp;path" lrecl=32767 truncover;
input line $varying32767. lrecl;
search="&amp;amp;search";
pattern = cats('/', search, '/i');
regex = prxparse(pattern);
if missing(regex) then do;
put "ERROR: Ungültiger regulärer Ausdruck.";
stop;
end;
zeilen_nr = _N_;
count = 0;
pos = prxmatch(regex, line);
if pos &amp;gt; 0 then do;
count + 1;
temp_line = substr(line, pos + 1);
do while (prxmatch(regex, temp_line) &amp;gt; 0);
count + 1;
temp_line = substr(temp_line, prxmatch(regex, temp_line) + 1);
end;
end;
output;
run;
proc print data=prxmatch;
var zeilen_nr count;
run;
%mend matcher_prxmatch;

%matcher_prxmatch(_____a.txt, SYS);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can someone explain to me why the error occurs?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 14:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960720#M43159</guid>
      <dc:creator>Dimax</dc:creator>
      <dc:date>2025-03-03T14:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter  as a search string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960727#M43160</link>
      <description>&lt;P&gt;Run the same code without the macro and you will be able to clearly see the LINE that is causing the error.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    data prxmatch;
2      length pos count zeilen_nr 8 line $32767 regex pattern $100 lrecl 8
2  ! search $100;
3      infile text lrecl=32767 truncover;
4      input line $varying32767. lrecl;
5      search="SYS";
6      pattern = cats('/', search, '/i');
7      regex = prxparse(pattern);
8      if missing(regex) then do;
9        put "ERROR: Ungültiger regulärer Ausdruck.";
10       stop;
11     end;
12     zeilen_nr = _N_;
13     count = 0;
14     pos = prxmatch(regex, line);
15     if pos &amp;gt; 0 then do;
16       count + 1;
17       temp_line = substr(line, pos + 1);
NOTE: Variable "temp_line" was given a default length of 32767 as the result
      of a function call.  If you do not like this, please use a LENGTH
      statement to declare "temp_line".
18       do while (prxmatch(regex, temp_line) &amp;gt; 0);
19         count + 1;
20         temp_line = substr(temp_line, prxmatch(regex,temp_line) + 1);
21       end;
22     end;
23     output;
24   run;

NOTE: Numeric values have been converted to character
      values at the places given by: (Line):(Column).
      7:11
NOTE: Variable lrecl is uninitialized.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you are defining REGEX as a CHARACTER variable, but it needs to be a NUMERIC variable.&lt;/P&gt;
&lt;P&gt;You are also trying to use LRECL in the INPUT statement to specify the length for the $VARYING informat when you never set LRECL to any value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data prxmatch;
  length pos count zeilen_nr 8 line temp_line $32767 regex 8 pattern $100 search $100;
  infile text lrecl=32767 truncover;
  input ;
  line = _infile_;
  search="SYS";
  pattern = cats('/', search, '/i');
  regex = prxparse(pattern);
  if missing(regex) then do;
    put "ERROR: Ungültiger regulärer Ausdruck.";
    stop;
  end;
  zeilen_nr = _N_;
  count = 0;
  pos = prxmatch(regex, line);
  if pos &amp;gt; 0 then do;
    count + 1;
    temp_line = substr(line, pos + 1);
    do while (prxmatch(regex, temp_line) &amp;gt; 0);
      count + 1;
      temp_line = substr(temp_line, prxmatch(regex,temp_line) + 1);
    end;
  end;
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Mar 2025 14:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960727#M43160</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-03-03T14:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter  as a search string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960729#M43161</link>
      <description>regex 8 is defined as numeric&lt;BR /&gt;because prxparse(pattern); return pattern id&lt;BR /&gt;NOTE: Numeric values have been converted to character&lt;BR /&gt;values at the places given by: (Line):(Column).&lt;BR /&gt;7:11 this is because file path contains numbers</description>
      <pubDate>Mon, 03 Mar 2025 15:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960729#M43161</guid>
      <dc:creator>Dimax</dc:creator>
      <dc:date>2025-03-03T15:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter  as a search string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960731#M43162</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/473968"&gt;@Dimax&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;regex 8 is defined as numeric&lt;BR /&gt;because prxparse(pattern); return pattern id&lt;BR /&gt;NOTE: Numeric values have been converted to character&lt;BR /&gt;values at the places given by: (Line):(Column).&lt;BR /&gt;7:11 this is because file path contains numbers&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show us the ENTIRE log for this macro. Showing us tiny little bits of the log really isn't helpful. Please click on the &amp;lt;/&amp;gt; icon and paste the log into the window that appears.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1715196634946.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96351i414DE7EE2D1B5DE6/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1715196634946.png" alt="PaigeMiller_0-1715196634946.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 15:18:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960731#M43162</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-03-03T15:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter  as a search string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960734#M43163</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/473968"&gt;@Dimax&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;regex 8 is defined as numeric&lt;BR /&gt;because prxparse(pattern); return pattern id&lt;BR /&gt;NOTE: Numeric values have been converted to character&lt;BR /&gt;values at the places given by: (Line):(Column).&lt;BR /&gt;7:11 this is because file path contains numbers&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Actual the reverse.&amp;nbsp; REGEX is defined as CHARACTER because of the LENGTH statement.&amp;nbsp; PRXPARSE() function returns a numeric value which is then converted into a character string to store into REGEX.&amp;nbsp; &amp;nbsp;So REGEX ends up with a value like '&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This then causes the later errors when REGEX is used as the input to the PRXMATCH() function call.&amp;nbsp; &amp;nbsp;Since REGEX is character instead of numeric PRXMATCH() is attempting to interpret the value as a new regular expression instead of using the one previously compiled by the PRXPARSE() function call.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 15:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960734#M43163</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-03-03T15:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter  as a search string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960737#M43164</link>
      <description>&lt;P&gt;Get the SAS code to work before trying to convert it into a macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let search=12;
data prxmatch;
  length zeilen_nr pos count 8 search $100 line temp_line $32767 regex 8 ;
  infile text lrecl=32767 truncover;
  input line $char32767.;
  zeilen_nr + 1;
  if zeilen_nr=1 then do;
    search="&amp;amp;search";
    regex=prxparse("/&amp;amp;search/i");
    if missing(regex) then do;
      put "ERROR: Ungültiger regulärer Ausdruck.";
      stop;
    end;
  end;
  retain search regex;
  count = 0;
  temp_line = line;
  do until(pos=0);
    pos = prxmatch(regex, temp_line);
    if pos &amp;gt; 0 then do;
      count + 1;
      temp_line = substr(temp_line, pos + 1);
    end;
  end;
  drop regex pos temp_line;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;     zeilen_
Obs     nr    count  search                        line

  1      1      1      12    Name=Alfred Sex=M Age=14 Height=69 Weight=112.5
  2      2      0      12    Name=Alice Sex=F Age=13 Height=56.5 Weight=84
  3      3      0      12    Name=Barbara Sex=F Age=13 Height=65.3 Weight=98
  4      4      0      12    Name=Carol Sex=F Age=14 Height=62.8 Weight=102.5
  5      5      0      12    Name=Henry Sex=M Age=14 Height=63.5 Weight=102.5
  6      6      1      12    Name=James Sex=M Age=12 Height=57.3 Weight=83
  7      7      1      12    Name=Jane Sex=F Age=12 Height=59.8 Weight=84.5
  8      8      1      12    Name=Janet Sex=F Age=15 Height=62.5 Weight=112.5
  9      9      0      12    Name=Jeffrey Sex=M Age=13 Height=62.5 Weight=84
 10     10      1      12    Name=John Sex=M Age=12 Height=59 Weight=99.5
 11     11      0      12    Name=Joyce Sex=F Age=11 Height=51.3 Weight=50.5
 12     12      0      12    Name=Judy Sex=F Age=14 Height=64.3 Weight=90
 13     13      1      12    Name=Louise Sex=F Age=12 Height=56.3 Weight=77
 14     14      1      12    Name=Mary Sex=F Age=15 Height=66.5 Weight=112
 15     15      0      12    Name=Philip Sex=M Age=16 Height=72 Weight=150
 16     16      2      12    Name=Robert Sex=M Age=12 Height=64.8 Weight=128
 17     17      0      12    Name=Ronald Sex=M Age=15 Height=67 Weight=133
 18     18      0      12    Name=Thomas Sex=M Age=11 Height=57.5 Weight=85
 19     19      1      12    Name=William Sex=M Age=15 Height=66.5 Weight=112
&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Mar 2025 15:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960737#M43164</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-03-03T15:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter  as a search string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960739#M43165</link>
      <description>&lt;P&gt;This is really complicated... I had &lt;CODE&gt;length regex 8&lt;/CODE&gt;, which I thought meant numeric 8 bytes. I changed it to &lt;CODE&gt;length regex 8.&lt;/CODE&gt; and the error disappeared. Then I changed it back to &lt;CODE&gt;length regex 8&lt;/CODE&gt;, and I still didn't get an error.&amp;nbsp; I also thank everyone for their help.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 15:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960739#M43165</guid>
      <dc:creator>Dimax</dc:creator>
      <dc:date>2025-03-03T15:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter  as a search string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960740#M43166</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/473968"&gt;@Dimax&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is really complicated... I had &lt;CODE&gt;length regex 8&lt;/CODE&gt;, which I thought meant numeric 8 bytes. I changed it to &lt;CODE&gt;length regex 8.&lt;/CODE&gt; and the error disappeared. Then I changed it back to &lt;CODE&gt;length regex 8&lt;/CODE&gt;, and I still didn't get an error.&amp;nbsp; I also thank everyone for their help.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The period makes no difference.&amp;nbsp; Lengths are always integers.&lt;/P&gt;
&lt;P&gt;You had this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length ... regex pattern $100 ..;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which defines REGEX and PATTERN as length $100.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2025 15:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960740#M43166</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-03-03T15:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro parameter  as a search string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960742#M43167</link>
      <description>yeah ..this was my mistake</description>
      <pubDate>Mon, 03 Mar 2025 15:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-parameter-as-a-search-string/m-p/960742#M43167</guid>
      <dc:creator>Dimax</dc:creator>
      <dc:date>2025-03-03T15:59:07Z</dc:date>
    </item>
  </channel>
</rss>

