<?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 I cant get prxmatch to work with %SYSFUNC in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-cant-get-prxmatch-to-work-with-SYSFUNC/m-p/636391#M189069</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to take an array as input to my macro, along with the variables that go into each array dimension.&amp;nbsp; To perform my processing, I need to split the input into the array name and the variable defining each dimension.&amp;nbsp; The relevant portion of code I am having trouble with is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ProcessArray(in_array= );
%let text_array= "&amp;amp;in_array";
%let _re = %SYSFUNC(prxparse("!(.+)\((.+)\)!"));
%let match = %SYSFUNC(prxmatch(&amp;amp;_re, &amp;amp;text_array));
%put &amp;amp;match;
%if &amp;amp;match %then
%do;
/* name of array */
%let HNAME = %SYSFUNC(prxposn(&amp;amp;_re, 1, &amp;amp;text_array)); *might need to use VVALUEX;
/* comma separated classifiers*/
%let _cstring = %SYSFUNC(prxposn(&amp;amp;_re, 2, &amp;amp;text_array));
%end;
%else %put "ERROR: regex failed match to function input";

%put &amp;amp;=HNAME;
%put &amp;amp;=_cstring;


%mend;

data test();
%ProcessArray(in_array=HARRAY(classifier1,classifier2,classifier3, classifier4, classifier5));

/* put "NOTE: &amp;amp;ndims"; */

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;error message:&lt;/P&gt;&lt;DIV class="sasSource"&gt;MLOGIC(PROCESSARRAY): %PUT &amp;amp;=HNAME&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;WARNING: Apparent symbolic reference HNAME not resolved.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;HNAME&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(PROCESSARRAY): %PUT &amp;amp;=_cstring&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;WARNING: Apparent symbolic reference _CSTRING not resolved&lt;/DIV&gt;&lt;PRE class="sasLog"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However the same code not done in the macro step works fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro ProcessArray(in_array = );

		/* Separating array input and arrayname  */
		_text="&amp;amp;in_array";
 		_re = prxparse("/(.+)\((.+)\)/");
 		if prxmatch(_re, _text) then 
 			do;
				/* name of array */
 				HNAME = prxposn(_re, 1, _text); *might need to use VVALUEX;
				/* comma separated classifiers*/
				_cstring = prxposn(_re, 2, _text);
 			end;	
 		else put "ERROR: regex failed match to function input";	
 		
 		put "NOTE: " HNAME=;
 		put "NOTE: " _cstring=;&lt;BR /&gt;%mend;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I want to see is HNAME=HARRAY, _cstring= classifier1,classifier2,classifier3, classifier4, classifier5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 31 Mar 2020 21:48:09 GMT</pubDate>
    <dc:creator>weg</dc:creator>
    <dc:date>2020-03-31T21:48:09Z</dc:date>
    <item>
      <title>I cant get prxmatch to work with %SYSFUNC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-cant-get-prxmatch-to-work-with-SYSFUNC/m-p/636391#M189069</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to take an array as input to my macro, along with the variables that go into each array dimension.&amp;nbsp; To perform my processing, I need to split the input into the array name and the variable defining each dimension.&amp;nbsp; The relevant portion of code I am having trouble with is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ProcessArray(in_array= );
%let text_array= "&amp;amp;in_array";
%let _re = %SYSFUNC(prxparse("!(.+)\((.+)\)!"));
%let match = %SYSFUNC(prxmatch(&amp;amp;_re, &amp;amp;text_array));
%put &amp;amp;match;
%if &amp;amp;match %then
%do;
/* name of array */
%let HNAME = %SYSFUNC(prxposn(&amp;amp;_re, 1, &amp;amp;text_array)); *might need to use VVALUEX;
/* comma separated classifiers*/
%let _cstring = %SYSFUNC(prxposn(&amp;amp;_re, 2, &amp;amp;text_array));
%end;
%else %put "ERROR: regex failed match to function input";

%put &amp;amp;=HNAME;
%put &amp;amp;=_cstring;


%mend;

data test();
%ProcessArray(in_array=HARRAY(classifier1,classifier2,classifier3, classifier4, classifier5));

/* put "NOTE: &amp;amp;ndims"; */

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;error message:&lt;/P&gt;&lt;DIV class="sasSource"&gt;MLOGIC(PROCESSARRAY): %PUT &amp;amp;=HNAME&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;WARNING: Apparent symbolic reference HNAME not resolved.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;HNAME&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;MLOGIC(PROCESSARRAY): %PUT &amp;amp;=_cstring&lt;/DIV&gt;&lt;DIV class="sasWarning"&gt;WARNING: Apparent symbolic reference _CSTRING not resolved&lt;/DIV&gt;&lt;PRE class="sasLog"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However the same code not done in the macro step works fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro ProcessArray(in_array = );

		/* Separating array input and arrayname  */
		_text="&amp;amp;in_array";
 		_re = prxparse("/(.+)\((.+)\)/");
 		if prxmatch(_re, _text) then 
 			do;
				/* name of array */
 				HNAME = prxposn(_re, 1, _text); *might need to use VVALUEX;
				/* comma separated classifiers*/
				_cstring = prxposn(_re, 2, _text);
 			end;	
 		else put "ERROR: regex failed match to function input";	
 		
 		put "NOTE: " HNAME=;
 		put "NOTE: " _cstring=;&lt;BR /&gt;%mend;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I want to see is HNAME=HARRAY, _cstring= classifier1,classifier2,classifier3, classifier4, classifier5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 21:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-cant-get-prxmatch-to-work-with-SYSFUNC/m-p/636391#M189069</guid>
      <dc:creator>weg</dc:creator>
      <dc:date>2020-03-31T21:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: I cant get prxmatch to work with %SYSFUNC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-cant-get-prxmatch-to-work-with-SYSFUNC/m-p/636393#M189070</link>
      <description>&lt;P&gt;Remove the quotes.&lt;/P&gt;
&lt;P&gt;%sysfunc() lifts SAS functions on macro level and macro language is purely text based so you don't need to quote strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ProcessArray(in_array= );
  %let text_array= &amp;amp;in_array;
  %let _re = %SYSFUNC(prxparse(/(.+)\((.+)\)/));
  %let match = %SYSFUNC(prxmatch(&amp;amp;_re, &amp;amp;text_array));
  %put &amp;amp;match;
  %if &amp;amp;match %then
    %do;
      /* name of array */
      %let HNAME = %SYSFUNC(prxposn(&amp;amp;_re, 1, &amp;amp;text_array));

      *might need to use VVALUEX;
      /* comma separated classifiers*/
      %let _cstring = %SYSFUNC(prxposn(&amp;amp;_re, 2, &amp;amp;text_array));
    %end;
  %else %put "ERROR: regex failed match to function input";
  %put &amp;amp;=HNAME;
  %put &amp;amp;=_cstring;
%mend;

data test();
  %ProcessArray(in_array=HARRAY(classifier1,classifier2,classifier3, classifier4, classifier5));

  /* put "NOTE: &amp;amp;ndims"; */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;HNAME=HARRAY
_CSTRING=classifier1,classifier2,classifier3, classifier4, classifier5
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 21:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-cant-get-prxmatch-to-work-with-SYSFUNC/m-p/636393#M189070</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-31T21:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: I cant get prxmatch to work with %SYSFUNC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-cant-get-prxmatch-to-work-with-SYSFUNC/m-p/636397#M189071</link>
      <description>&lt;P&gt;Wow I cant believe I didnt get that. I had another portion of my code throwing an error that made me not catch it, and its the same problem so I was wondering how I would fix it.&amp;nbsp; The non macro part that iterates through the _cstring&lt;/P&gt;&lt;PRE&gt;do i=1 by 1 until (parse = ' ');
   		parse = scan(_cstring, i, ',')&lt;BR /&gt;end;&lt;/PRE&gt;&lt;P&gt;I'm assuming I need to get rid of the quotes, so I figured I should turn it into something like this:&lt;/P&gt;&lt;PRE&gt;%let delimiter = ,;&lt;BR /&gt;%let i = 0;&lt;BR /&gt;%do %until (%length(&amp;amp;parse) =  0);
 			%let i = %eval (&amp;amp;i +1);
   			%let parse = %SYSFUNC(SCAN(&amp;amp;_cstring, &amp;amp;i, &amp;amp;delimiter));&lt;BR /&gt;%end;&lt;/PRE&gt;&lt;P&gt;but then I get&lt;/P&gt;&lt;PRE&gt; ERROR: The function SCAN referenced by the %SYSFUNC or %QSYSFUNC macro function has too many 
        arguments.&lt;/PRE&gt;&lt;P&gt;so I'm assuming its the &amp;amp;delimiter portion that is messed up?&amp;nbsp; how do you get around not being able to use quotes in %sysfunc?&amp;nbsp; I know %scan exists but it has the same error message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 22:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-cant-get-prxmatch-to-work-with-SYSFUNC/m-p/636397#M189071</guid>
      <dc:creator>weg</dc:creator>
      <dc:date>2020-03-31T22:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: I cant get prxmatch to work with %SYSFUNC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-cant-get-prxmatch-to-work-with-SYSFUNC/m-p/636399#M189072</link>
      <description>&lt;P&gt;You need macro quoting.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _cstring=classifier1,classifier2,classifier3, classifier4, classifier5;
%let delimiter = ,;
%let i=2;
%let parse=%scan(%nrbquote(&amp;amp;_cstring),&amp;amp;i,%nrbquote(&amp;amp;delimiter));
%put &amp;amp;=parse;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;PARSE=classifier2
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 22:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-cant-get-prxmatch-to-work-with-SYSFUNC/m-p/636399#M189072</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-31T22:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: I cant get prxmatch to work with %SYSFUNC</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-cant-get-prxmatch-to-work-with-SYSFUNC/m-p/636409#M189076</link>
      <description>&lt;P&gt;You need macro quoting,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let string=A,B,C;
%let dlm= ,;
%do i=1 %to %sysfunc(countw(%str(&amp;amp;string),%str(&amp;amp;dlm)));
  %let word=%scan(%str(&amp;amp;string),%str(&amp;amp;dlm));
  %put &amp;amp;=i &amp;amp;=word;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or better planning.&amp;nbsp; It does not make any sense to use comma as the delimiter.&amp;nbsp; Space is a better delimiter if you are going to use the string to generate commands.&amp;nbsp; For example if STRING is list of variable names.&lt;/P&gt;
&lt;P&gt;But otherwise just use some other character that is not in the data and is not critical to writing code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let string=A|B|C;
%let dlm= |;
%do i=1 %to %sysfunc(countw(&amp;amp;string,&amp;amp;dlm));
  %let word=%scan(&amp;amp;string,&amp;amp;dlm);
  %put &amp;amp;=i &amp;amp;=word;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Apr 2020 01:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-cant-get-prxmatch-to-work-with-SYSFUNC/m-p/636409#M189076</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-01T01:45:07Z</dc:date>
    </item>
  </channel>
</rss>

