<?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: PRX with a single quote in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448195#M112726</link>
    <description>This appears to work as well.  Thanks for the suggestion!</description>
    <pubDate>Fri, 23 Mar 2018 15:31:54 GMT</pubDate>
    <dc:creator>Ryanb2</dc:creator>
    <dc:date>2018-03-23T15:31:54Z</dc:date>
    <item>
      <title>PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/447989#M112624</link>
      <description>&lt;P&gt;I created a data dictionary with a column for field name and another column with the expected pattern (PRX) for each field.&amp;nbsp; For example, the name fields allow letters, spaces, hyphens, commas, and apostrophes; so the pattern listed for those fields is /[A-Z\-\,\' ]/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I import the data dictionary then create macro variables to hold a listing of field names separated by space, and patterns separated by ~.&amp;nbsp; However, when the code iterates through the patterns it chokes on the single quote.&amp;nbsp; I've tried to put double quotes around&amp;nbsp;the patterns in the data dictionary,&amp;nbsp;and I tried putting&amp;nbsp;""&amp;amp;doubleQuotes"" around&amp;nbsp;the macro variable,&amp;nbsp;and tried %bquote, but I can't seem to find a combination that works.&amp;nbsp; The SAS code and&amp;nbsp;error message can be found below.&amp;nbsp; The error message below corresponds to pattern /[A-Z\-\,\' ]/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Closing delimiter "/" not found after regular expression "/[A-Z\-\,\".&lt;/P&gt;
&lt;P&gt;ERROR: The regular expression passed to the function PRXMATCH contains a syntax error.&lt;/P&gt;
&lt;P&gt;NOTE: Argument 1 to function PRXMATCH('/[A-Z\-\,\','L''ittle '[12 of 60 characters shown]) at&lt;/P&gt;
&lt;P&gt;line 13 column 42 is invalid.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any advice is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Ryan&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select VARNAME, PATTERN
	into :varlist separated by ' ',
		:pattern separated by '~'
	from Ccbf_dd
	where PATTERN ne '';
quit;
%let cntlist = &amp;amp;sqlobs;
%put &amp;amp;varlist;
%macro test(); %put %bquote(&amp;amp;pattern); %mend test; %test;

%macro Val_check();
	data QC_CCBF_values;
		set CCBF;
		length Issue_desc $250;

		Issue_desc=''; /* Initialize Issue_desc */

		%do i = 1 %to &amp;amp;cntlist;  /* iterate through the list of fields */
			%let varname= %scan(%bquote(&amp;amp;varlist.), &amp;amp;i., %str(' '));  /* scans through the list of fields and assigns them one by one to the &amp;amp;varname macro var */
			%let patternM= %scan(%bquote(&amp;amp;pattern.), &amp;amp;i., %str('~'));  /* scans through the list of patterns and assigns them one by one to the &amp;amp;patternM macro var */
				if &amp;amp;varname ne '' and prxmatch("&amp;amp;patternM",&amp;amp;varname.) eq 0 then Issue_desc=catx('; ',Issue_desc,"&amp;amp;varname");
		%end;
	run;
%mend Val_check;
%Val_check();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 22:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/447989#M112624</guid>
      <dc:creator>Ryanb2</dc:creator>
      <dc:date>2018-03-22T22:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448046#M112654</link>
      <description>&lt;P&gt;Try using %qscan instead of %scan.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 03:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448046#M112654</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-03-23T03:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448048#M112655</link>
      <description>&lt;P&gt;This works. Changes highlighted&lt;/P&gt;
&lt;PRE&gt;%let varname= %scan(%bquote(&amp;amp;varlist.), &amp;amp;i., &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;%str( )&lt;/STRONG&gt;&lt;/FONT&gt;);  
%let patternM= %&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;qscan&lt;/FONT&gt;&lt;/STRONG&gt;(%bquote(&amp;amp;pattern), &amp;amp;i., &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;~&lt;/FONT&gt;&lt;/STRONG&gt;);  
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 04:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448048#M112655</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-03-23T04:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448067#M112665</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/46197"&gt;@Ryanb2&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Besides of the challenge with the single quote I believe that your current logic won't return the result you're after. The RegEx as per your code will only return something as invalid&amp;nbsp;(value of zero)&amp;nbsp;if ALL characters in the string are invalid.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 07:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448067#M112665</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-23T07:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448075#M112670</link>
      <description>&lt;P&gt;Inded&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;is right.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to "&lt;SPAN&gt;allow letters, spaces, hyphens, commas, and apostrophes&lt;/SPAN&gt;" you probably want&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;BADFLAG=prxmatch("/[^A-Z ,'-]/i", VAR);&lt;/FONT&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 07:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448075#M112670</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-03-23T07:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448105#M112683</link>
      <description>&lt;P&gt;Rather than messing round with tons of Klingon syntax (macro quoting), why not just single-quote the patterns from the start:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select VARNAME, quote(trim(PATTERN),"'")
	into :varlist separated by ' ',
		:pattern separated by '~'
	from Ccbf_dd
	where PATTERN ne '';
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can then change your PRXMATCH call to PRXMATCH(&amp;amp;PatternM,&amp;amp;Varname), and drop all the&amp;nbsp;macro quoting. And you&amp;nbsp;will not have to worry about patterns&amp;nbsp;containing your string delimiter ("~", in this case), just use&amp;nbsp;%sysfunc(Scan(&amp;amp;pattern,&amp;amp;i,~,Q)),&amp;nbsp;instead of %SCAN or %QSCAN, then delimiters in patterns will not matter.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 12:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448105#M112683</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-03-23T12:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448168#M112714</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/46197"&gt;@Ryanb2&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;This is for me one of these use cases where generating and including code is much easier to implement and debug than using macro code. People are of course different - but that's how my brain works.&lt;/P&gt;
&lt;P&gt;Below some code which illustrates the approach.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data parameterTable;
  varname='varA'; pattern="/[^A-Z ,'-]/oi"; output;
  varname='VarB'; pattern="/[^xyz]/oi";   ;output;
  stop;
run;

filename codegen temp;
data _null_;
/*  file print;*/
  file codegen;
  set parameterTable;

  put @2 'if ' varname 'ne " " and prxmatch("' pattern +(-1)'",strip(' varname +(-1)')) &amp;gt; 0'; 
  put @4 'then Issue_desc=catx("; ",Issue_desc,"' varname +(-1)'");';
run;


data CCBF;
  varA='abc'; varB='xyz';output;
  varA='a1b'; varB='xyz';output;
  varA='abc'; varB='xbz';output;
  varA='a1b'; varB='xbz';output;
  stop;
run;

data QC_CCBF_values;
  set CCBF;
  length Issue_desc $250;
  Issue_desc=''; 
  %include codegen / source2;
run;
          
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Besides of easily writing the generated code to the output window (file print) during development, I also like that it's easy to read in the SAS log when executed.&lt;/P&gt;
&lt;PRE&gt;52         data QC_CCBF_values;
53           set CCBF;
54           length Issue_desc $250;
55           Issue_desc='';
56           %include codegen / source2;
NOTE: %INCLUDE (level 1) file CODEGEN is file C:\Users\ssapam\AppData\Local\Temp\SEG8912\SAS Temporary 
      Files\_TD9428_SSAPAM_\#LN00019.
57        + if varA ne " " and prxmatch("/[^A-Z ,'-]/oi",strip(varA)) &amp;gt; 0
58        +   then Issue_desc=catx("; ",Issue_desc,"varA");
59        + if VarB ne " " and prxmatch("/[^xyz]/oi",strip(VarB)) &amp;gt; 0
60        +   then Issue_desc=catx("; ",Issue_desc,"VarB");
NOTE: %INCLUDE (level 1) ending.
61         run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Mar 2018 14:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448168#M112714</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-23T14:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448185#M112720</link>
      <description>Thanks PGStats!  That seems to have done the job.  I appreciate your help.</description>
      <pubDate>Fri, 23 Mar 2018 15:16:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448185#M112720</guid>
      <dc:creator>Ryanb2</dc:creator>
      <dc:date>2018-03-23T15:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448188#M112721</link>
      <description>&lt;P&gt;You are absolutely right.&amp;nbsp; I didn't include the ^.&amp;nbsp; I so focusing on the single quote issue.&amp;nbsp; Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 15:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448188#M112721</guid>
      <dc:creator>Ryanb2</dc:creator>
      <dc:date>2018-03-23T15:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448195#M112726</link>
      <description>This appears to work as well.  Thanks for the suggestion!</description>
      <pubDate>Fri, 23 Mar 2018 15:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448195#M112726</guid>
      <dc:creator>Ryanb2</dc:creator>
      <dc:date>2018-03-23T15:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448197#M112728</link>
      <description>&lt;P&gt;This works too.&amp;nbsp; Thanks for the suggestion!&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 15:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448197#M112728</guid>
      <dc:creator>Ryanb2</dc:creator>
      <dc:date>2018-03-23T15:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: PRX with a single quote</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448200#M112731</link>
      <description>Thanks Patrick.  I'll try this out sometime.</description>
      <pubDate>Fri, 23 Mar 2018 15:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PRX-with-a-single-quote/m-p/448200#M112731</guid>
      <dc:creator>Ryanb2</dc:creator>
      <dc:date>2018-03-23T15:33:59Z</dc:date>
    </item>
  </channel>
</rss>

