<?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: remove text inside nested parentheses using PRX in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851718#M336663</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438035"&gt;@sas504&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&amp;nbsp;Thanks for the feedback. That explains why the RegEx "worked" even though I couldn't understand why.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below some actually working code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd;
  input (have_str want_str) (:$20.);
  datalines;
TTCCH((AA)A)D,TTCCHD
TTCCH(TT(A(xx)A)A)D,TTCCHD
ABCDEFGH(TTTT)YYYABT,ABCDEFGHYYYABT
CCGHT()TTCA,CCGHTTTCA
CHATTTT(A),CHATTTT
TATTTT(A),TATTTT
CCGG()TTT,CCGGTTT
CGGAAAA(AA),CGGAAAA
CGGAAAA(AA)T,CGGAAAAT
CGGAAAA((AA)T),CGGAAAA
AAT(BB)ADAA(CCDC)AXC,AATADAAAXC 
AAAAA,AAAAA
;

data want;
  set have;
  derived_str=have_str;
  do _i=1 to 99;
    _derived_str=derived_str;
    derived_str=prxchange('s/\([^()]*\)//',1,strip(derived_str));
    if _derived_str=derived_str then leave;
  end;
  check_flg= derived_str=want_str;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 31 Dec 2022 22:23:29 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2022-12-31T22:23:29Z</dc:date>
    <item>
      <title>remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851655#M336633</link>
      <description>&lt;P&gt;Hi there!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been able to get data with nested parentheses to the point of now only having balanced parentheses, but I'm struggling with removing the text (and ideally parentheses also) when there is nesting. Would ideally like to use prxchange and felt like I kept getting close but not quite there.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Have:&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Want:&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;TTCCH((AA)A)D&lt;/TD&gt;&lt;TD&gt;TTCCHD&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;TTCCH(TT(AA)A)D&lt;/TD&gt;&lt;TD&gt;TTCCHD&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABCDEFGH(TTTT)YYYABT&lt;/TD&gt;&lt;TD&gt;ABCDEFGHYYYABT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CCGHT()TTCA&lt;/TD&gt;&lt;TD&gt;CCGHTTTCA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CHATTTT(A)&lt;/TD&gt;&lt;TD&gt;CHATTTT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;TATTTT(A)&lt;/TD&gt;&lt;TD&gt;TATTTT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CCGG()TTT&lt;/TD&gt;&lt;TD&gt;CCGGTTT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CGGAAAA(AA)&lt;/TD&gt;&lt;TD&gt;CGGAAAA&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CGGAAAA(AA)T&lt;/TD&gt;&lt;TD&gt;CGGAAAAT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CGGAAAA((AA)T)&lt;/TD&gt;&lt;TD&gt;CGGAAAA&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An example already tried but did not work with nesting... although works great with other situations for me:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/remove-text-inside-brackets-including-brackets/m-p/477689#M123082" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/remove-text-inside-brackets-including-brackets/m-p/477689#M123082&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Novice here with prxchange, but I was trying something along the lines of&amp;nbsp; &amp;nbsp; &amp;nbsp; new= prxchange('s/[\(+\w+\)+]*//i',-1,old)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would appreciate suggestions, thanks so much!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 00:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851655#M336633</guid>
      <dc:creator>sas504</dc:creator>
      <dc:date>2022-12-31T00:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851656#M336634</link>
      <description>&lt;P&gt;Is this an exercise to learn PRX? Otherwise it's a whole lot easier just to do a word scan:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
  set Have;
  want = scan(have,1,'(');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 31 Dec 2022 01:24:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851656#M336634</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-12-31T01:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851658#M336635</link>
      <description>&lt;P&gt;For your sample data below RegEx will do the job. It works because &lt;FONT face="arial black,avant garde" color="#0000FF"&gt;&lt;STRONG&gt;.*&lt;/STRONG&gt;&lt;/FONT&gt; is greedy.&amp;nbsp;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/p0s9ilagexmjl8n1u7e1t1jfnzlk.htm#n1rvql3zwk9g5bn1uzfzcycc3zg5" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.2/lefunctionsref/p0s9ilagexmjl8n1u7e1t1jfnzlk.htm#n1rvql3zwk9g5bn1uzfzcycc3zg5&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd;
  input (have_str want_str) (:$20.);
  datalines;
TTCCH((AA)A)D,TTCCHD
TTCCH(TT(AA)A)D,TTCCHD
ABCDEFGH(TTTT)YYYABT,ABCDEFGHYYYABT
CCGHT()TTCA,CCGHTTTCA
CHATTTT(A),CHATTTT
TATTTT(A),TATTTT
CCGG()TTT,CCGGTTT
CGGAAAA(AA),CGGAAAA
CGGAAAA(AA)T,CGGAAAAT
CGGAAAA((AA)T),CGGAAAA
;

data want;
  set have;
  length derived_str $20;
  derived_str=prxchange('s/\(.*\)//',1,strip(have_str));
  check_flg= derived_str=want_str;
run;

proc print data=want;
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-1672452122218.png" style="width: 546px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78944i5C2D632329E497F4/image-dimensions/546x266?v=v2" width="546" height="266" role="button" title="Patrick_0-1672452122218.png" alt="Patrick_0-1672452122218.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 02:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851658#M336635</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-12-31T02:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851664#M336639</link>
      <description>&lt;P&gt;Thank you so much, Patrick. This is so close to a complete fix. Is there a way where this won't remove the letters between closed parentheses also? It is throwing out everything between closed parentheses as well now. I have long strings that may have many sets of closed parentheses.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have:&lt;/P&gt;&lt;P&gt;AAT(BB)ADAA(CCDC)AXC&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want:&lt;/P&gt;&lt;P&gt;AATADAAAXC&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 05:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851664#M336639</guid>
      <dc:creator>sas504</dc:creator>
      <dc:date>2022-12-31T05:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851667#M336640</link>
      <description>&lt;P&gt;As long as you've got balanced brackets below should work.&lt;/P&gt;
&lt;P&gt;I've played around with some variations of the RegEx and I'm currently still trying to understand myself why below RegEx works even without having a repeated search/replace (-1 as 2nd parameter to prxmatch) and why it also works with a greedy search for anything but a closing bracket&amp;nbsp;&lt;FONT face="courier new,courier"&gt;[^\)]*&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd;
  input (have_str want_str) (:$20.);
  datalines;
TTCCH((AA)A)D,TTCCHD
TTCCH(TT(A(xx)A)A)D,TTCCHD
ABCDEFGH(TTTT)YYYABT,ABCDEFGHYYYABT
CCGHT()TTCA,CCGHTTTCA
CHATTTT(A),CHATTTT
TATTTT(A),TATTTT
CCGG()TTT,CCGGTTT
CGGAAAA(AA),CGGAAAA
CGGAAAA(AA)T,CGGAAAAT
CGGAAAA((AA)T),CGGAAAA
AAT(BB)ADAA(CCDC)AXC,AATADAAAXC 
AAAAA,AAAAA
;

data want;
  set have;
  length derived_str $20;
  derived_str=prxchange('s/\([^\)]*\)//',1,strip(want_str));
  check_flg= derived_str=want_str;
run;

proc print data=want;
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-1672469429034.png" style="width: 496px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78945i71EA83E18872DFC8/image-dimensions/496x263?v=v2" width="496" height="263" role="button" title="Patrick_0-1672469429034.png" alt="Patrick_0-1672469429034.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I found an interesting discussion around this topic &lt;A href="https://stackoverflow.com/questions/546433/regular-expression-to-match-balanced-parentheses" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;- but as long as your brackets are balanced and you don't want to pick anything between matching brackets, things should work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1672469486490.png" style="width: 655px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78946i7D8EA0033D0933F0/image-dimensions/655x634?v=v2" width="655" height="634" role="button" title="Patrick_1-1672469486490.png" alt="Patrick_1-1672469486490.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 07:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851667#M336640</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-12-31T07:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851682#M336644</link>
      <description>&lt;P&gt;It is depended on how many nested parentheses you have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd;
  input (have_str want_str) (:$20.);
  datalines;
TTCCH((AA)A)D,TTCCHD
TTCCH(TT(A(xx)A)A)D,TTCCHD
ABCDEFGH(TTTT)YYYABT,ABCDEFGHYYYABT
CCGHT()TTCA,CCGHTTTCA
CHATTTT(A),CHATTTT
TATTTT(A),TATTTT
CCGG()TTT,CCGGTTT
CGGAAAA(AA),CGGAAAA
CGGAAAA(AA)T,CGGAAAAT
CGGAAAA((AA)T),CGGAAAA
AAT(BB)ADAA(CCDC)AXC,AATADAAAXC 
AAAAA,AAAAA
;

data want;
  set have;
  length derived_str $20;
derived_str=have_str ;
do i=1 to 99;
  derived_str=prxchange('s/\([^()]*\)//',-1,strip(derived_str));
end;
  check_flg= derived_str=want_str;
  drop i;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 31 Dec 2022 09:33:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851682#M336644</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-12-31T09:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851688#M336645</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp; The code you're proposing was pretty much how I've done it initially.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1672480127139.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78952iD8BC31F2AC127E1B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1672480127139.png" alt="Patrick_1-1672480127139.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But then "playing" with both code and additional sample data I found out that the do loop isn't required, that the RegEx only needs the closing parenthesis and that I even don't need to set -1 as parameter (fully working code in my previous post.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_2-1672480237255.png" style="width: 432px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78953iFB405177E1D5A38C/image-dimensions/432x27?v=v2" width="432" height="27" role="button" title="Patrick_2-1672480237255.png" alt="Patrick_2-1672480237255.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;WHY this returns the desired result I still don't fully understand but feel once I do I will have gained deeper insight into the SAS RegEx implementation and how function prxchange() really works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 09:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851688#M336645</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-12-31T09:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851691#M336648</link>
      <description>&lt;P&gt;Take another look at your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;derived_str=prxchange('s/\([^\)]*\)//',1,strip(want_str));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are modifying the WANT_STR variable, not the HAVE_STR. Using HAVE_STR gives different results.&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 11:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851691#M336648</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-12-31T11:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851701#M336652</link>
      <description>&lt;P&gt;Thank you so much for the resources and help, Patrick. I wasn't able to get the latest solution you posted to work, but I think it was due to this part as I don't in reality have the 'want' string:&amp;nbsp;derived_str=prxchange('s/\([^\)]*\)//',1,strip(&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;want_str&lt;/FONT&gt;&lt;/STRONG&gt;));&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 15:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851701#M336652</guid>
      <dc:creator>sas504</dc:creator>
      <dc:date>2022-12-31T15:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851702#M336653</link>
      <description>&lt;P&gt;Thank you so much for the solution, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;. This worked very well for every situation I threw at it! I greatly appreciate it!&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 15:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851702#M336653</guid>
      <dc:creator>sas504</dc:creator>
      <dc:date>2022-12-31T15:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851712#M336657</link>
      <description>&lt;P&gt;I see this topic has already been solved, but it may be worth expanding on&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;'s suggestion of the SCAN function (assuming PRX is not required).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just take the first "word" (using "(" as a word-separator) and the last "word" (using ")" as the separator), and concatenate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  new =scan(have_str,1,'(') || scan(have_str,-1,')');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above assumes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;There is at least one "(" and one ")".&lt;/LI&gt;
&lt;LI&gt;The left parenthesis does not appear in the first character of the string.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;No loops needed, regardless of how many pairs of parentheses in the string.&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 17:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851712#M336657</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-12-31T17:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851713#M336658</link>
      <description>&lt;P&gt;If you allow the pattern to stop at the first right parenthesis then you can take the wrong string from nested groups.&lt;/P&gt;
&lt;P&gt;Take for example:&lt;/P&gt;
&lt;PRE&gt;TTCCH(TT(AA)A)D&lt;/PRE&gt;
&lt;P&gt;Going from the first ( to the first ) would remove (TT(AA) and leave A).&lt;/P&gt;
&lt;P&gt;Excluding the the ( means that it finds the (AA).&amp;nbsp; But then that leave (TTA) which is what makes the need for the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can however use another regex to know when to stop looping. (Let me rename the variables so that STRING is the original value and WANT is the output variable.)&lt;/P&gt;
&lt;P&gt;So first copy the original string.&amp;nbsp; Then keep removing groups as long as there are anymore groups to remove.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; want=string;
 do while(prxmatch('/\([^()]*\)/',want));
   want = prxchange('s/\([^()]*\)//',-1,want);
 end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the -1 to make it find disjointed groups in a single pass.&amp;nbsp; So to strip something like&amp;nbsp;CG(GA)AAA(AA)T will only take one pass through the loop.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 17:45:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851713#M336658</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-31T17:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851715#M336660</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;- Nice correction, but then I realised my attempt doesn't doesn't cater for multiple sets of parenthises so I think that a DO UNTIL (or WHILE) loop is still needed for that case.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 19:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851715#M336660</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-12-31T19:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851716#M336661</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;- Nice correction, but then I realised my attempt doesn't doesn't cater for multiple sets of parenthises so I think that a DO UNTIL (or WHILE) loop is still needed for that case.&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/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp; &amp;nbsp;I don't think a DO loop is required.&amp;nbsp; My understanding is that all text from the left outer paren through the right outer paren is to be eliminated, leaving the leftmost "word" preceding the first "(" and the rightmost word following the last ")".&amp;nbsp; &amp;nbsp; No need to account for interior parens.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 20:20:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851716#M336661</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-12-31T20:20:58Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851717#M336662</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;- This is the case I looked at&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have:&lt;/P&gt;
&lt;P&gt;AAT(BB)ADAA(CCDC)AXC&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want:&lt;/P&gt;
&lt;P&gt;AATADAAAXC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your solution gives:&amp;nbsp;AATAXC&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 31 Dec 2022 20:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851717#M336662</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-12-31T20:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851718#M336663</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438035"&gt;@sas504&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;&amp;nbsp;Thanks for the feedback. That explains why the RegEx "worked" even though I couldn't understand why.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below some actually working code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd;
  input (have_str want_str) (:$20.);
  datalines;
TTCCH((AA)A)D,TTCCHD
TTCCH(TT(A(xx)A)A)D,TTCCHD
ABCDEFGH(TTTT)YYYABT,ABCDEFGHYYYABT
CCGHT()TTCA,CCGHTTTCA
CHATTTT(A),CHATTTT
TATTTT(A),TATTTT
CCGG()TTT,CCGGTTT
CGGAAAA(AA),CGGAAAA
CGGAAAA(AA)T,CGGAAAAT
CGGAAAA((AA)T),CGGAAAA
AAT(BB)ADAA(CCDC)AXC,AATADAAAXC 
AAAAA,AAAAA
;

data want;
  set have;
  derived_str=have_str;
  do _i=1 to 99;
    _derived_str=derived_str;
    derived_str=prxchange('s/\([^()]*\)//',1,strip(derived_str));
    if _derived_str=derived_str then leave;
  end;
  check_flg= derived_str=want_str;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 31 Dec 2022 22:23:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851718#M336663</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-12-31T22:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851727#M336664</link>
      <description>Patrick,&lt;BR /&gt;Yeah. I steal your most of code.&lt;BR /&gt;My code is trying to remove nest parentheses VIA do loop. For example:&lt;BR /&gt;TTCCH(TT(A(xx)A)A)D,TTCCHD&lt;BR /&gt;first time is --&amp;gt; TTCCH(TT(AA)A)D,TTCCHD&lt;BR /&gt;second time is --&amp;gt; TTCCH(TTA)D,TTCCHD&lt;BR /&gt;third time is --&amp;gt; TTCCHD,TTCCHD&lt;BR /&gt;&lt;BR /&gt;About the 1 or -1 ,it doesn't matter you use 1 or -1, as long as 99 is big enough.</description>
      <pubDate>Sun, 01 Jan 2023 08:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851727#M336664</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-01-01T08:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851751#M336676</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;- This is the case I looked at&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have:&lt;/P&gt;
&lt;P&gt;AAT(BB)ADAA(CCDC)AXC&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want:&lt;/P&gt;
&lt;P&gt;AATADAAAXC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your solution gives:&amp;nbsp;AATAXC&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Ah.&amp;nbsp; &amp;nbsp;Right you are.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jan 2023 16:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851751#M336676</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-01-01T16:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: remove text inside nested parentheses using PRX</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851752#M336677</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; - I thought about it long and hard and realised that any non-PRX solution is likely to be no better than the PRX one &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jan 2023 19:44:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-text-inside-nested-parentheses-using-PRX/m-p/851752#M336677</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-01-01T19:44:56Z</dc:date>
    </item>
  </channel>
</rss>

