<?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: PERL REG EX vs. %STR() in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/722871#M224216</link>
    <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; sometimes it can be so easy....&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;: do you also have any suggestions for the REG EX command?&lt;/P&gt;</description>
    <pubDate>Tue, 02 Mar 2021 15:01:50 GMT</pubDate>
    <dc:creator>FK1</dc:creator>
    <dc:date>2021-03-02T15:01:50Z</dc:date>
    <item>
      <title>PERL REG EX vs. %STR()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/722865#M224212</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am parsing SAS-Code in SAS, which results in creating a table that has a variable named "Source_Code". For every observation in this table, the value of "Source_Code" is a code line of a SAS program.&lt;/P&gt;&lt;P&gt;In particular, I am interested in how to find x-command, which were used in the parsed SAS-Code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets imagine, I have a program called prog1.sas which consists of the following lines of code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
set sashelp.class;
x "rm /this/is/a/path/to/a/file.txt" ;
     x "rm /this/is/another/path/to/a/file2.txt";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now, as you can see the second x-command is &lt;STRONG&gt;preceeded by couple of blanks.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run my SAS-Parsing-Program that parses the above prog1.sas, everything works fine, in the sense, that each line is being parsed and written into a table called "parsed_code".&lt;/P&gt;&lt;P&gt;What I want is, for the program to indicate, if in the parsed program any x-command-line has been used (which is the case for line 3 and 4!)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore, I tried using PERL Regular Expression and also using %STR - Quoting Function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
set work.parsed_code;
	if _N_=1 then do;
	RETAIN  x_cmd_patternID;

    x_cmd_pattern = "/x[[:blank:]]/";

    x_cmd_patternID=prxparse(x_cmd_pattern);
	end;
reg_ex_flag_x_cmd= prxmatch(x_cmd_patternID,Source_Code); 

flag_x_cmd = index(upcase(Source_Code), ("%STR(X %")")) gt 0;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regarding the PERL RegEx-Espression, how can I "tell" the command to look for the string 'x "', i.e. &amp;lt;x blank one unmatched pair of double quotes&amp;gt;&amp;nbsp; regardless, if there are leading blanks in front of the "x"? And also regardless of how many blanks are between the "x" and the double quotes...?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was trying to make sense of the&amp;nbsp;&lt;A title="Tables of Perl Regular Expression (PRX) Metacharacters" href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0s9ilagexmjl8n1u7e1t1jfnzlk.htm&amp;amp;locale=en" target="_self"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0s9ilagexmjl8n1u7e1t1jfnzlk.htm&amp;amp;locale=en&lt;/A&gt;&amp;nbsp;but so far, without successful results...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem, I have, when using the %STR() function in EG is, that all successive code is being altered in its color, indicating, that EG thinks, this is all part of a unmatched quote! Even though I escaped the unmatched pair of double quotes with a percent sign.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any tips how tell EG to mask the unmatched pair of double quotes?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;FK1&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 14:44:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/722865#M224212</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2021-03-02T14:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: PERL REG EX vs. %STR()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/722868#M224214</link>
      <description>&lt;P&gt;You don't need %STR&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input source_code $char80.;
  *set work.parsed_code;
   if _N_=1 then do;
	  RETAIN  x_cmd_patternID;
     x_cmd_pattern = "/x[[:blank:]]/";
     x_cmd_patternID=prxparse(x_cmd_pattern);
	  end;
   reg_ex_flag_x_cmd= prxmatch(x_cmd_patternID,Source_Code); 
   flag_x_cmd = index(upcase(Source_Code), 'X "') gt 0;
   cards4;
data _NULL_;
set sashelp.class;
x "rm /this/is/a/path/to/a/file.txt" ;
    x "rm /this/is/another/path/to/a/file2.txt";
run;
;;;;
run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Mar 2021 14:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/722868#M224214</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2021-03-02T14:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: PERL REG EX vs. %STR()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/722871#M224216</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; sometimes it can be so easy....&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;: do you also have any suggestions for the REG EX command?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 15:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/722871#M224216</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2021-03-02T15:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: PERL REG EX vs. %STR()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/722907#M224238</link>
      <description>&lt;P&gt;It is important to note that the expression&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;index(upcase(Source_Code), 'X "')&lt;/LI-CODE&gt;
&lt;P&gt;is not adequate to identify all X command syntax&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x      "cmd";
x 'cmd';
x %sysfunc(quote(&amp;amp;cmd));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To name just three&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 16:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/722907#M224238</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2021-03-02T16:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: PERL REG EX vs. %STR()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723100#M224341</link>
      <description>&lt;P&gt;Tanks, for your remarks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;This is exactly, why I was trying to use regular expressions to incorporate cases, where there&amp;nbsp; are things like trailing or leading blanks, double quotes vs single quotes, etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, I am not well equipped when it comes to PRX- expressions.&lt;/P&gt;&lt;P&gt;So far, I came up with this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    x_cmd_pattern = '/x[[:blank:]]"/';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How do I modify this expressions to incorporate trailing or leading blanks,&amp;nbsp;double quotes vs single quotes, etc.?&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 09:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723100#M224341</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2021-03-03T09:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: PERL REG EX vs. %STR()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723102#M224342</link>
      <description>&lt;P&gt;Something like this should find most macro-less calls you describe:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;FLAG=prxmatch('/\A\s*x\s+[''"]/i',STRING);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;If you want to catch calls that use the macro language, you need to define the perimeter.&lt;/P&gt;
&lt;P&gt;There is almost no limit to how complex a macro expression can be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 10:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723102#M224342</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-03T10:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: PERL REG EX vs. %STR()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723524#M224527</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;Do you also maybe have a tip how to "catch" filename pipe commands?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename &amp;lt;some arbitryry text of variable length&amp;gt; pipe;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I tell a Perl Regular Expression to interleave any number of letters between the word "filename" and the word "pipe"?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;FLAG=prxmatch('/\s*filename\s[[:alpha:]]*pipe/i',STRING);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Mar 2021 17:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723524#M224527</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2021-03-04T17:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: PERL REG EX vs. %STR()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723534#M224530</link>
      <description>&lt;P&gt;Would it be sufficient to search the string for the word PIPE findw(upcase(source), 'PIPE') after you find FILENAME.statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that you can also have an INFILE statement with the PIPE option that does not use a FILENAME&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    command = '/usr/bin/find ....';
    INFILE DUMMY PIPE filevar=command end=eof;
    do while(not eof);
      input;
      end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stop;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Mar 2021 17:40:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723534#M224530</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2021-03-04T17:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: PERL REG EX vs. %STR()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723584#M224544</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;FLAG=prxmatch('/\s*filename\s+[[:alpha:]]{1,8}pipe\s/i',STRING);&lt;/LI-CODE&gt;
&lt;P&gt;Another expression to catch some infile statements as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;showed, could be:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;FLAG=prxmatch('/[\s;]*[filename|infile]\s+[[:alpha:]]{1,8}pipe\s/i',STRING);&lt;/LI-CODE&gt;
&lt;P&gt;This will also catch a filename preceded by a ;&amp;nbsp; but will not catch a filename created using the filename function, or a filename spanning several lines.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 19:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723584#M224544</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-04T19:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: PERL REG EX vs. %STR()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723586#M224546</link>
      <description>&lt;P&gt;Also note that&amp;nbsp; &amp;nbsp;&lt;FONT face="courier new,courier"&gt;filename _A1 '.';&amp;nbsp;&lt;/FONT&gt;&amp;nbsp;is valid, so looking for letters only is insufficient.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 19:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PERL-REG-EX-vs-STR/m-p/723586#M224546</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-04T19:43:24Z</dc:date>
    </item>
  </channel>
</rss>

