<?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: replace strings among (), [], {}, ' ', &amp;quot; &amp;quot; as the same number of X in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564749#M158442</link>
    <description>Many thanks</description>
    <pubDate>Sun, 09 Jun 2019 13:26:08 GMT</pubDate>
    <dc:creator>Alexxxxxxx</dc:creator>
    <dc:date>2019-06-09T13:26:08Z</dc:date>
    <item>
      <title>replace strings among (), [], {}, ' ', " " as the same number of X</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564320#M158276</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I replace strings among (), [], {}, ' ', " " as the same number of Xs&lt;/P&gt;&lt;P&gt;for the following words,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
input NAME :&amp;amp; $800.;
cards;
ALLCELLS BIOLOGICAL TECHNOLOGY (SHAN) COMPANY
ALLEGRO ASIA TECHNOLOGY (D.B.A.)
ALLEN BROTHERS 'FITTINGS'
ALLEN R. NELSON ENGINEERING (1997)
ALLENS MESHCO (PROPRIETARY &amp;amp; MANUFACTURING)
ALLERGY THERAPEUTICS {UK}
ALLES GOED [PTY] LIMITED, TRADING AS PIPE &amp;amp; PLANT INSULATION
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I expect to get&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NAME&lt;/TD&gt;&lt;TD&gt;Expect&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALLCELLS BIOLOGICAL TECHNOLOGY (SHAN) COMPANY&lt;/TD&gt;&lt;TD&gt;ALLCELLS BIOLOGICAL TECHNOLOGY (XXXX) COMPANY&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALLEGRO ASIA TECHNOLOGY (D.B.A.)&lt;/TD&gt;&lt;TD&gt;ALLEGRO ASIA TECHNOLOGY (X.X.X.)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALLEN BROTHERS 'FITTINGS'&lt;/TD&gt;&lt;TD&gt;ALLEN BROTHERS 'XXXXXXXX'&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALLEN R. NELSON ENGINEERING (1997)&lt;/TD&gt;&lt;TD&gt;ALLEN R. NELSON ENGINEERING (XXXX)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALLENS MESHCO (PROPRIETARY &amp;amp; MANUFACTURING)&lt;/TD&gt;&lt;TD&gt;ALLENS MESHCO (XXXXXXXXXXX &amp;amp; XXXXXXXXXXXXX)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALLERGY THERAPEUTICS {UK}&lt;/TD&gt;&lt;TD&gt;ALLERGY THERAPEUTICS {XX}&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ALLES GOED [PTY] LIMITED, TRADING AS PIPE &amp;amp; PLANT INSULATION&lt;/TD&gt;&lt;TD&gt;ALLES GOED [XXX] LIMITED, TRADING AS PIPE &amp;amp; PLANT INSULATION&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Could you please give me some suggestions about this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 22:03:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564320#M158276</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-06-06T22:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings among (), [], {}, ' ', " " as the same number of X</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564330#M158280</link>
      <description>&lt;P&gt;This is pretty ugly but it appears to work. It is using the ability of the SUBSTR function to edit part of a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
input NAME :&amp;amp; $800.;
length char1 char2 $1;
do chars = '()', "''", '{}', '[]';
  char1 = substr(chars,1,1);
  char2 = substr(chars,2,1);
  if findc(NAME,char1) and findc(NAME,char2) then 
    substr(name, findc(NAME,char1) + 1, findc(NAME,char2, findc(NAME,char1)+1) - findc(NAME,char1)-1)
    = repeat('X', findc(NAME,char2, findc(NAME,char1)+1) - findc(NAME,char1)-1) ; 
end;
put name = ;
cards;
ALLCELLS BIOLOGICAL TECHNOLOGY (SHAN) COMPANY
ALLEGRO ASIA TECHNOLOGY (D.B.A.)
ALLEN BROTHERS 'FITTINGS'
ALLEN R. NELSON ENGINEERING (1997)
ALLENS MESHCO (PROPRIETARY &amp;amp; MANUFACTURING)
ALLERGY THERAPEUTICS {UK}
ALLES GOED [PTY] LIMITED, TRADING AS PIPE &amp;amp; PLANT INSULATION
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 02:49:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564330#M158280</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-06-07T02:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings among (), [], {}, ' ', " " as the same number of X</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564679#M158413</link>
      <description>&lt;P&gt;If there is only one pattern in an obs, that would be easy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
input NAME :&amp;amp; $800.;
call scan(name,2,p,l,'()[]{}''"','m');
temp=prxchange('s/\w/X/i',-1,substr(name,p,l));
substr(name,p,l)=temp;
cards;
ALLCELLS BIOLOGICAL TECHNOLOGY (SHAN) COMPANY
ALLEGRO ASIA TECHNOLOGY (D.B.A.)
ALLEN BROTHERS 'FITTINGS'
ALLEN R. NELSON ENGINEERING (1997)
ALLENS MESHCO (PROPRIETARY &amp;amp; MANUFACTURING)
ALLERGY THERAPEUTICS {UK}
ALLES GOED [PTY] LIMITED, TRADING AS PIPE &amp;amp; PLANT INSULATION
;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Jun 2019 16:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564679#M158413</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-06-08T16:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings among (), [], {}, ' ', " " as the same number of X</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564749#M158442</link>
      <description>Many thanks</description>
      <pubDate>Sun, 09 Jun 2019 13:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564749#M158442</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-06-09T13:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings among (), [], {}, ' ', " " as the same number of X</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564750#M158443</link>
      <description>Thanks for your suggestion</description>
      <pubDate>Sun, 09 Jun 2019 13:26:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564750#M158443</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2019-06-09T13:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings among (), [], {}, ' ', " " as the same number of X</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564784#M158456</link>
      <description>&lt;P&gt;Other options:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT1;
  set HAVE;
  TMP=NAME;
  do while(1);
    NEW=prxchange('s/ (\[.*?) [^X] (.*?\]) /$1X$2/x', -1, TMP);
    NEW=prxchange('s/ ( {.*?) [^X] (.*?} ) /$1X$2/x', -1, NEW);
    NEW=prxchange('s/ (\(.*?) [^X] (.*?\)) /$1X$2/x', -1, NEW);
    NEW=prxchange('s/ (''.*?) [^X] (.*?'') /$1X$2/x', -1, NEW);
    if TMP=NEW then leave ;
    else TMP=NEW;
  end;
  keep NAME NEW;
run;
         
data WANT2; 
  set HAVE;                              
  do PAIRS = '()', "''", '{}', '[]';
    POS1=findc(NAME,char(PAIRS,1));
    POS2=findc(NAME,char(PAIRS,2),POS1+1);     
    if 0 &amp;lt; POS1 &amp;lt; POS2-1 then 
      substr(NAME, POS1 + 1, POS2 - POS1 -1) = repeat('X', POS2 - POS1 - 2) ; 
  end;
run;    
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jun 2019 23:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564784#M158456</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-06-09T23:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings among (), [], {}, ' ', " " as the same number of X</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564847#M158482</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; Do you know why the DO UNTIL loop is needed in my example, and the -1 recursion in prxchange is not enough? &lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2019 10:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564847#M158482</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-06-10T10:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings among (), [], {}, ' ', " " as the same number of X</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564896#M158498</link>
      <description>Sorry. No idea.</description>
      <pubDate>Mon, 10 Jun 2019 14:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564896#M158498</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-06-10T14:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: replace strings among (), [], {}, ' ', " " as the same number of X</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564899#M158500</link>
      <description>Sorry. No idea.</description>
      <pubDate>Mon, 10 Jun 2019 14:26:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-strings-among-quot-quot-as-the-same-number-of-X/m-p/564899#M158500</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-06-10T14:26:55Z</dc:date>
    </item>
  </channel>
</rss>

