<?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: Unbalanced quotation in variable assignment and PRXMATCH in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920585#M362566</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442038"&gt;@PamG&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks.&amp;nbsp; That will not work for me as I have 50 such variables.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442038"&gt;@PamG&lt;/a&gt;&amp;nbsp;The more you show and tell us what you have, the better we can provide advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below sample code accepts as many lists (variables) as you have to then dynamically process these without the need for any further code change.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.var_val;
  infile datalines truncover;
  input name:$32. value:$16.;
  datalines;
var1 24900
var1 24901
var1 24910
var1 24911
var1 24920
var1 24921
var1 24930
var2 25070
var2 25071
var2 25072
var2 25073
var2 25080
var2 25081
var2 25082
var2 25083
;
run;

proc sort data=work.var_val nodupkey;
  by name value;
run;

data work.master;
  infile datalines truncover;
  length id source_str $40. match_flg_expected 3;
  input id match_flg_expected source_str $40.;
  datalines;
1 1 agvd98475249014374 25080 24930 25080 
2 1 99999250729999
3 0 111112507911111
;

proc sql noprint;
  select count(name), max(cnt_value) into :n_names trimmed, :n_values trimmed
  from
    (
      select name, count(distinct value) as cnt_value
      from work.var_val
      group by name
    )
  ;
quit;

/*data demo(keep=id search_var match_val pos len);*/
data work.demo(drop=_:);
 if _n_=1 then
  do;
    _names_ind =1;
    _values_ind=0;
    do until(_done);
      set work.var_val(keep=name value rename=(name=_name value=_value)) end=_done;
      by _name;
      array _values{&amp;amp;n_values} $16 _temporary_;
      array _names {&amp;amp;n_names}  $32 _temporary_;
      array _prxid {&amp;amp;n_names}   8  _temporary_;
      _values_ind+1;
      _values[_values_ind]=_value;
      if last._name then
        do;
          _names[_names_ind]=_name;
          _prxid[_names_ind]=prxparse(cats('/(',catx(')|(',of _values[*]),')/'));
          _names_ind+1;
          _values_ind=0;
          call missing(of _values[*]);
        end;
    end;
  end;

  set work.master;
  length search_var $32 match_val $16;
  _stop = length(source_str);
  do _i=1 to &amp;amp;n_names;
    _start = 1;
    call prxnext(_prxid[_i], _start, _stop, trim(source_str), pos, len);
    if pos&amp;gt;0 then search_var=_names[_i];
    do while (pos &amp;gt; 0);
       match_val = substr(trim(source_str), pos, len);
       output;
       call prxnext(_prxid[_i], _start, _stop, trim(source_str), pos, len);
    end;
  end;
  /* below line only if also neew to output source rows with any match */
  if missing(search_var) then output;
run;

proc print data=work.demo;
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_0-1710656769609.png" style="width: 579px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94684iC90E8D7364850B46/image-dimensions/579x152?v=v2" width="579" height="152" role="button" title="Patrick_0-1710656769609.png" alt="Patrick_0-1710656769609.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 17 Mar 2024 06:31:43 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-03-17T06:31:43Z</dc:date>
    <item>
      <title>Unbalanced quotation in variable assignment and PRXMATCH</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920524#M362536</link>
      <description>&lt;P&gt;I have to search for set of strings that when used in PRXMATCH comes to more than 262 characters long and SAS gives an unbalanced quotation marks warning.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;NOTE: The quoted string currently being processed has become more than 262 characters long. &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;You might have unbalanced quotation marks.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The run finishes inspite of the warning and I am wondering if I should break the PRXMATCH into several statements.&amp;nbsp; A sample code is given below.&amp;nbsp; The code&amp;nbsp; runs fine and I am wondering if I should ignore the warning.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
var="24900|24901|24910|24911|24920|24921|24930|24931|24940|24941|24950|24951|24960|24961|24970|24971|24980|24981|24990|24991|25000|25001|25002|25003|25010|25011|25012|25013|25020|25021|25022|25023|25030|25031|25032|25033|25040|25041|25042|25043|25050|25051|25052|25053|25060|25061|25062|25063|25070|25071|25072|25073|25080|25081|25082|25083|25090|25091|25092|25093|36641|V5391|V5867";
varlength=Length(var);
%put var;
%put varlength;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Mar 2024 22:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920524#M362536</guid>
      <dc:creator>PamG</dc:creator>
      <dc:date>2024-03-15T22:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: Unbalanced quotation in variable assignment and PRXMATCH</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920526#M362538</link>
      <description>&lt;P&gt;As is often the case, "there is an option for that".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option noquotelenmax;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lesysoptsref/n1j7a6mgalhqo5n11kv0vbpbx277.htm" target="_self"&gt;QUOTELENMAX System Option&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 23:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920526#M362538</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-03-15T23:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Unbalanced quotation in variable assignment and PRXMATCH</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920530#M362540</link>
      <description>&lt;P&gt;Besides of noquotelenmax you could also just create your macro variable differently - which should also make it easier to maintain your list of values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data values;
  infile datalines truncover;
  input var:$16.;
  datalines;
24900
24901
24910
24911
24920
24921
24930
;
run;

proc sql noprint;
  select var into :var_list separated by '|'
  from values;
quit;

%put &amp;amp;=var_list;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Mar 2024 04:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920530#M362540</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-16T04:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Unbalanced quotation in variable assignment and PRXMATCH</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920550#M362549</link>
      <description>&lt;P&gt;Thanks.&amp;nbsp; That will not work for me as I have 50 such variables.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 13:22:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920550#M362549</guid>
      <dc:creator>PamG</dc:creator>
      <dc:date>2024-03-16T13:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: Unbalanced quotation in variable assignment and PRXMATCH</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920551#M362550</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442038"&gt;@PamG&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442038"&gt;@PamG&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var="24900|24901|24910|24911|24920|24921|24930|24931|24940|24941|24950|24951|24960|24961|24970|24971|24980|24981|24990|24991|25000|25001|25002|25003|25010|25011|25012|25013|25020|25021|25022|25023|25030|25031|25032|25033|25040|25041|25042|25043|25050|25051|25052|25053|25060|25061|25062|25063|25070|25071|25072|25073|25080|25081|25082|25083|25090|25091|25092|25093|36641|V5391|V5867";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that the length of this particular regular expression can be reduced from 377 to merely 44 characters:&lt;/P&gt;
&lt;PRE&gt;249[0-9][01]|250[0-9][0-3]|36641|V5391|V5867&lt;/PRE&gt;
&lt;P&gt;This makes it not only more readable, but also about seven times faster (on my workstation) when used with PRXMATCH. And, of course, it avoids&amp;nbsp;the "... &lt;FONT face="courier new,courier"&gt;more than 262 characters&lt;/FONT&gt; ..." note in the log.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 13:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920551#M362550</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-03-16T13:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Unbalanced quotation in variable assignment and PRXMATCH</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920585#M362566</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442038"&gt;@PamG&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks.&amp;nbsp; That will not work for me as I have 50 such variables.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442038"&gt;@PamG&lt;/a&gt;&amp;nbsp;The more you show and tell us what you have, the better we can provide advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below sample code accepts as many lists (variables) as you have to then dynamically process these without the need for any further code change.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.var_val;
  infile datalines truncover;
  input name:$32. value:$16.;
  datalines;
var1 24900
var1 24901
var1 24910
var1 24911
var1 24920
var1 24921
var1 24930
var2 25070
var2 25071
var2 25072
var2 25073
var2 25080
var2 25081
var2 25082
var2 25083
;
run;

proc sort data=work.var_val nodupkey;
  by name value;
run;

data work.master;
  infile datalines truncover;
  length id source_str $40. match_flg_expected 3;
  input id match_flg_expected source_str $40.;
  datalines;
1 1 agvd98475249014374 25080 24930 25080 
2 1 99999250729999
3 0 111112507911111
;

proc sql noprint;
  select count(name), max(cnt_value) into :n_names trimmed, :n_values trimmed
  from
    (
      select name, count(distinct value) as cnt_value
      from work.var_val
      group by name
    )
  ;
quit;

/*data demo(keep=id search_var match_val pos len);*/
data work.demo(drop=_:);
 if _n_=1 then
  do;
    _names_ind =1;
    _values_ind=0;
    do until(_done);
      set work.var_val(keep=name value rename=(name=_name value=_value)) end=_done;
      by _name;
      array _values{&amp;amp;n_values} $16 _temporary_;
      array _names {&amp;amp;n_names}  $32 _temporary_;
      array _prxid {&amp;amp;n_names}   8  _temporary_;
      _values_ind+1;
      _values[_values_ind]=_value;
      if last._name then
        do;
          _names[_names_ind]=_name;
          _prxid[_names_ind]=prxparse(cats('/(',catx(')|(',of _values[*]),')/'));
          _names_ind+1;
          _values_ind=0;
          call missing(of _values[*]);
        end;
    end;
  end;

  set work.master;
  length search_var $32 match_val $16;
  _stop = length(source_str);
  do _i=1 to &amp;amp;n_names;
    _start = 1;
    call prxnext(_prxid[_i], _start, _stop, trim(source_str), pos, len);
    if pos&amp;gt;0 then search_var=_names[_i];
    do while (pos &amp;gt; 0);
       match_val = substr(trim(source_str), pos, len);
       output;
       call prxnext(_prxid[_i], _start, _stop, trim(source_str), pos, len);
    end;
  end;
  /* below line only if also neew to output source rows with any match */
  if missing(search_var) then output;
run;

proc print data=work.demo;
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_0-1710656769609.png" style="width: 579px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94684iC90E8D7364850B46/image-dimensions/579x152?v=v2" width="579" height="152" role="button" title="Patrick_0-1710656769609.png" alt="Patrick_0-1710656769609.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2024 06:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unbalanced-quotation-in-variable-assignment-and-PRXMATCH/m-p/920585#M362566</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-17T06:31:43Z</dc:date>
    </item>
  </channel>
</rss>

