<?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: how to use scan function to remove '(' in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-scan-function-to-remove/m-p/815533#M321907</link>
    <description>&lt;P&gt;Tom,&lt;/P&gt;
&lt;P&gt;I think PRX is the best choice.&lt;/P&gt;
&lt;P&gt;If data like the following,your code does not work !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards;
input string &amp;amp;:$50.;
cards;
Influenza Invalid,FLU-22 Invalid
Influenza Invalid(20),FLU-22 Invalid(2999)
Influenza Canceled(77),FLU-22 Canceled(77)
Influenza Negative,FLU-22 Positive
(Influenza)
;
run;

data want;
 set have;
 length string2 string3 $80.;
 do i=1 by 2 to countw(string,'()');
   string2=cats(string2,scan(string,i,'()'));
 end;

 string3 = prxchange('s/\(.*?\)//', -1, string);
 drop i;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 28 May 2022 10:51:17 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-05-28T10:51:17Z</dc:date>
    <item>
      <title>how to use scan function to remove '('</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-scan-function-to-remove/m-p/815491#M321890</link>
      <description>&lt;P&gt;Hello, can you help me get the following output? Basically I want to remove any values in "()" without using substr function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;current data:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Influenza Invalid,FLU-22 Invalid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Influenza Invalid(20),FLU-22 Invalid(2999)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Influenza Canceled(77),FLU-22 Canceled(77)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Influenza Negative,FLU-22 Positive&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;want data:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Influenza Invalid,FLU-22 Invalid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Influenza Invalid,FLU-22 Invalid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Influenza Canceled,FLU-22 Canceled&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Influenza Negative,FLU-22 Positive&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 20:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-scan-function-to-remove/m-p/815491#M321890</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2022-05-27T20:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to use scan function to remove '('</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-scan-function-to-remove/m-p/815495#M321892</link>
      <description>&lt;P&gt;Can you show the code you have tried?&amp;nbsp; Seems like maybe this would be a good a better task for regular expressions (PRXCHANGE).&amp;nbsp; To use SCAN(), I think you'd have to use a DO-loop, assuming you don't know how many sets of parentheses you might have in a value.&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 20:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-scan-function-to-remove/m-p/815495#M321892</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-05-27T20:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to use scan function to remove '('</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-scan-function-to-remove/m-p/815514#M321899</link>
      <description>&lt;P&gt;As Quentin suggested, regex replace will do it easily.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards;
input text &amp;amp;:$50.;
cards;
Influenza Invalid,FLU-22 Invalid
Influenza Invalid(20),FLU-22 Invalid(2999)
Influenza Canceled(77),FLU-22 Canceled(77)
Influenza Negative,FLU-22 Positive
;
run;

data want;
set have;
* lazily search for matching pair of parentheses and replace with empty string;
text_clean = prxchange('s/\(.*?\)//', -1, text);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 May 2022 22:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-scan-function-to-remove/m-p/815514#M321899</guid>
      <dc:creator>average_joe</dc:creator>
      <dc:date>2022-05-27T22:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to use scan function to remove '('</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-scan-function-to-remove/m-p/815517#M321901</link>
      <description>&lt;P&gt;I suspect that it will be better to use regular expressions instead, but you asked for SCAN() function so here you go.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
 length string2 $80.;
 do i=1 by 2 to countw(string,'()');
   string2=cats(string2,scan(string,i,'()'));
 end;
 drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs                      string                                   string2

 1     Influenza Invalid,FLU-22 Invalid              Influenza Invalid,FLU-22 Invalid
 2     Influenza Invalid(20),FLU-22 Invalid(2999)    Influenza Invalid,FLU-22 Invalid
 3     Influenza Canceled(77),FLU-22 Canceled(77)    Influenza Canceled,FLU-22 Canceled
 4     Influenza Negative,FLU-22 Positive            Influenza Negative,FLU-22 Positive

&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 May 2022 23:04:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-scan-function-to-remove/m-p/815517#M321901</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-27T23:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to use scan function to remove '('</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-scan-function-to-remove/m-p/815533#M321907</link>
      <description>&lt;P&gt;Tom,&lt;/P&gt;
&lt;P&gt;I think PRX is the best choice.&lt;/P&gt;
&lt;P&gt;If data like the following,your code does not work !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards;
input string &amp;amp;:$50.;
cards;
Influenza Invalid,FLU-22 Invalid
Influenza Invalid(20),FLU-22 Invalid(2999)
Influenza Canceled(77),FLU-22 Canceled(77)
Influenza Negative,FLU-22 Positive
(Influenza)
;
run;

data want;
 set have;
 length string2 string3 $80.;
 do i=1 by 2 to countw(string,'()');
   string2=cats(string2,scan(string,i,'()'));
 end;

 string3 = prxchange('s/\(.*?\)//', -1, string);
 drop i;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 May 2022 10:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-scan-function-to-remove/m-p/815533#M321907</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-05-28T10:51:17Z</dc:date>
    </item>
  </channel>
</rss>

