<?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: macro for searching and replacing a ( in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500512#M133313</link>
    <description>&lt;P&gt;Once you replace "(" with "_" do you also want to remove the ")" ?&lt;/P&gt;</description>
    <pubDate>Mon, 01 Oct 2018 19:17:26 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-10-01T19:17:26Z</dc:date>
    <item>
      <title>macro for searching and replacing a (</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500504#M133309</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a quick and easy way of searching and replacing a ( with an _&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;eg. %let x=Premium_Loans-44014(1);&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;%let y=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(tranwrd(&amp;amp;x,"(","_")); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Rob&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 18:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500504#M133309</guid>
      <dc:creator>rramcharan</dc:creator>
      <dc:date>2018-10-01T18:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: macro for searching and replacing a (</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500509#M133311</link>
      <description>&lt;P&gt;Is this what you are looking for?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 19:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500509#M133311</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-01T19:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: macro for searching and replacing a (</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500511#M133312</link>
      <description>&lt;P&gt;I can't see the code you are suggesting...sorry&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 19:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500511#M133312</guid>
      <dc:creator>rramcharan</dc:creator>
      <dc:date>2018-10-01T19:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: macro for searching and replacing a (</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500512#M133313</link>
      <description>&lt;P&gt;Once you replace "(" with "_" do you also want to remove the ")" ?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 19:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500512#M133313</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-01T19:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: macro for searching and replacing a (</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500513#M133314</link>
      <description>&lt;P&gt;yes&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 19:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500513#M133314</guid>
      <dc:creator>rramcharan</dc:creator>
      <dc:date>2018-10-01T19:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: macro for searching and replacing a (</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500520#M133317</link>
      <description>&lt;P&gt;Untested but should be workable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let part1 = %scan(%superq(macrovar), 1, %str(&lt;FONT color="#FF0000"&gt;%)%(&lt;/FONT&gt;));&lt;/P&gt;
&lt;P&gt;%let part2 = %scan(%superq(macrovar), 2, %str(&lt;FONT color="#FF0000"&gt;%)%(&lt;/FONT&gt;));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The pieces in &lt;FONT color="#FF0000"&gt;red&lt;/FONT&gt; are the way to refer to parentheses within the %STR function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are certain that there will always be parentheses, you could simply use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let result = &amp;amp;part1._&amp;amp;part2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there might be parentheses just some of the time you would need to add a macro to be able to use %if / %then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if %length(&amp;amp;part2)=0 %then %let result = &amp;amp;part1;&lt;/P&gt;
&lt;P&gt;%else %let result = &amp;amp;part1._&amp;amp;part2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a little clumsy (and untested at this point), but it's difficult for macro language to use parentheses as part of the syntax since they need to be treated as both text and as significant characters.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 19:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500520#M133317</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-01T19:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: macro for searching and replacing a (</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500527#M133320</link>
      <description>&lt;P&gt;Two other functions that may be useful:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SCAN() with () as the delimters to extract the portion before, within or after.&lt;/P&gt;
&lt;P&gt;COMPRESS() which can remove the characters indicated and return the string without the characters.&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/193009"&gt;@rramcharan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a quick and easy way of searching and replacing a ( with an _&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;eg. %let x=Premium_Loans-44014(1);&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;%let y=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(tranwrd(&amp;amp;x,"(","_")); &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Rob&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 19:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500527#M133320</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-01T19:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: macro for searching and replacing a (</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500539#M133325</link>
      <description>&lt;P&gt;you can prxchange. \( meaning escape starting of paerenthesis and&amp;nbsp; \) is closing of parenthesis (\d) is meant to capture a number.&lt;/P&gt;
&lt;P&gt;so&amp;nbsp;\((\d)\) means replace (\d) capture d (digit) and replace () with _&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;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=%str(Premium_Loans-44014(1));
%put &amp;amp;x;
%let y=%sysfunc(prxchange(s/\((\d)\)/_\1/,1, &amp;amp;x));
%put &amp;amp;y; 


output is 

 73         %let x= Premium_Loans-44014(1);
 74         %put &amp;amp;x;
 Premium_Loans-44014(1)
 75         %let y=%sysfunc(prxchange(s/\((\d)\)/_\1/,1, &amp;amp;x));
 76         %put &amp;amp;y;
 Premium_Loans-44014_1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 20:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500539#M133325</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-10-01T20:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: macro for searching and replacing a (</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500550#M133328</link>
      <description>&lt;P&gt;If you always have the pattern xxxxx(xxx) then %SCAN() is probably the easiest.&lt;/P&gt;
&lt;PRE&gt;160  %let x=Premium_Loans-44014(1);
161  %let y=%scan(&amp;amp;x,1,())_%scan(&amp;amp;x,2,());
162  %put &amp;amp;=y;
Y=Premium_Loans-44014_1&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Oct 2018 20:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500550#M133328</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-01T20:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: macro for searching and replacing a (</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500664#M133363</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=Premium_Loans-44014(1);
%put &amp;amp;x;
%let y=%sysfunc(translate(%bquote(&amp;amp;x),%str(_),%str(%()));
%put &amp;amp;y; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Oct 2018 10:41:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-for-searching-and-replacing-a/m-p/500664#M133363</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-02T10:41:44Z</dc:date>
    </item>
  </channel>
</rss>

