<?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 a string inside a macro variable value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261529#M50918</link>
    <description>&lt;P&gt;Would it be easier to make another macro variable to hold that part of the string and set that value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can TRANSTRN using SYSFUNC: &amp;nbsp;%SYSFUNC(TRANSTRN(source,from,to))&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let rule = %sysfunc(transtrn(%superq(rule),IV_PRT,IVPRL));&lt;/P&gt;</description>
    <pubDate>Tue, 05 Apr 2016 21:13:41 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2016-04-05T21:13:41Z</dc:date>
    <item>
      <title>Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261520#M50915</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let RULE=A.ROWID IN (SELECT TABLE_ROWID FROM IV_RPT.COMPARE_ERROR);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;I have a macro variable defined as above. &amp;nbsp;I need to search this value sometimes and replace ' IV_RPT.' with&lt;/P&gt;&lt;P&gt;' IVPRL.' before the macro variable is referenced later in my program. &amp;nbsp;Does SAS offer a Replace function of some type? &amp;nbsp;Any suggestions would be greatly appreciated. &amp;nbsp;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2016 20:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261520#M50915</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-04-05T20:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261526#M50917</link>
      <description>&lt;P&gt;I would think to use PERL. PRXChange could work here.&amp;nbsp; Here is a paper on this &lt;A href="http://analytics.ncsu.edu/sesug/2012/CT-03.pdf" target="_blank"&gt;http://analytics.ncsu.edu/sesug/2012/CT-03.pdf&lt;/A&gt; and here is some documentation on it &lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#n0frf578x6vno8n1w26b6qn2wlt5.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#n0frf578x6vno8n1w26b6qn2wlt5.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2016 21:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261526#M50917</guid>
      <dc:creator>ptimusk</dc:creator>
      <dc:date>2016-04-05T21:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261529#M50918</link>
      <description>&lt;P&gt;Would it be easier to make another macro variable to hold that part of the string and set that value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can TRANSTRN using SYSFUNC: &amp;nbsp;%SYSFUNC(TRANSTRN(source,from,to))&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let rule = %sysfunc(transtrn(%superq(rule),IV_PRT,IVPRL));&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2016 21:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261529#M50918</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-04-05T21:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261537#M50921</link>
      <description>&lt;P&gt;If you do use PERL can you makr my reply as a solution. thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2016 21:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261537#M50921</guid>
      <dc:creator>ptimusk</dc:creator>
      <dc:date>2016-04-05T21:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261544#M50923</link>
      <description>&lt;P&gt;Here is a simpler solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let RULE=A.ROWID IN (SELECT TABLE_ROWID FROM IV_RPT.COMPARE_ERROR);&lt;BR /&gt;%let RULE=%sysfunc(tranwrd(%superq(RULE),IV_RPT,IVRPT));&lt;BR /&gt;%put RULE=%superq(RULE);&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2016 21:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261544#M50923</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2016-04-05T21:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261546#M50925</link>
      <description>Hmm...doesn't seem to be working.</description>
      <pubDate>Tue, 05 Apr 2016 21:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261546#M50925</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-04-05T21:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261547#M50926</link>
      <description>It has to be done on the fly because the macro variable value actually comes from an Oracle table that stores the string. So I'm going to have to figure out a way to convert it. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;</description>
      <pubDate>Tue, 05 Apr 2016 21:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261547#M50926</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-04-05T21:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261551#M50927</link>
      <description>&lt;P&gt;The PERL solution can help you be dynamic or 'on the fly'&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2016 22:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261551#M50927</guid>
      <dc:creator>ptimusk</dc:creator>
      <dc:date>2016-04-05T22:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261553#M50928</link>
      <description>&lt;P&gt;IF you are extracting the string value from a table, then you can do the string replacement within the sql using the TRANWRD/TRANSTRN functions!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on what kinda of SQL statement you are using, Implecit vs. Explicit, the function call location need to change to ensure optimal performance.&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>Tue, 05 Apr 2016 22:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261553#M50928</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2016-04-05T22:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261611#M50949</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rule=A.ROWID IN (SELECT TABLE_ROWID FROM IV_RPT.COMPAE_ERROR);

data _null_;
rule = tranwrd("&amp;amp;rule","IV_RPT.","IVPRL.");
call symput("rule",trim(rule));
run;

%put rule=&amp;amp;rule;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want it to be more parameterized, wrap it into a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rule=A.ROWID IN (SELECT TABLE_ROWID FROM IV_RPT.COMPARE_ERROR);

%macro tran_mac(macvar,previous,replace);
%global &amp;amp;macvar;
data _null_;
length string $1000; * make big enough for all use cases;
string = tranwrd("&amp;amp;&amp;amp;&amp;amp;macvar.","&amp;amp;previous","&amp;amp;replace");
call symput("&amp;amp;macvar",trim(string));
run;
%mend;

%tran_mac(rule,IV_RPT.,IVPRL.);

%put rule=&amp;amp;rule;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Apr 2016 07:22:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261611#M50949</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-04-06T07:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261753#M50992</link>
      <description>&lt;P&gt;I agree : unknowingly, I came up with the same solution. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;BR /&gt;%superq is not necessary, though. %bquote is sufficient.&lt;BR /&gt;The requester is always right, they say.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 14:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261753#M50992</guid>
      <dc:creator>ronan</dc:creator>
      <dc:date>2016-04-06T14:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a string inside a macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261764#M51000</link>
      <description>&lt;P&gt;Hmm I left the testing for you.&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/79805"&gt;@buechler66&lt;/a&gt; wrote:&lt;BR /&gt;Hmm...doesn't seem to be working.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2016 14:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-string-inside-a-macro-variable-value/m-p/261764#M51000</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-04-06T14:50:51Z</dc:date>
    </item>
  </channel>
</rss>

