<?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: Problem in using tranwrd function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-in-using-tranwrd-function/m-p/37769#M7523</link>
    <description>Hi.Patrick is right.&lt;BR /&gt;
To avoid to overwrite F8,you need to change the code a little bit to retain the changed value of F8.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let mvar1= rahim1 ramu1 sham1;&lt;BR /&gt;
%let mvar= rahim ramu sham;&lt;BR /&gt;
%let val=3;&lt;BR /&gt;
&lt;BR /&gt;
data testing22;&lt;BR /&gt;
rahim="good";&lt;BR /&gt;
ramu="cool";&lt;BR /&gt;
sham="fine";&lt;BR /&gt;
rahim1="rahim";&lt;BR /&gt;
ramu1="ramu";&lt;BR /&gt;
sham1="akram";&lt;BR /&gt;
a="from rahim";output;&lt;BR /&gt;
a="from ramu";output;&lt;BR /&gt;
a="from akram";output;&lt;BR /&gt;
a="from aram";output;&lt;BR /&gt;
a="from &amp;amp;sham";output;&lt;BR /&gt;
a="from &amp;amp;sham;";output;&lt;BR /&gt;
rahim="good";output;&lt;BR /&gt;
ramu="cool";output;&lt;BR /&gt;
sham="fine";output;&lt;BR /&gt;
rahim1="rahim";output;&lt;BR /&gt;
ramu1="ramu";output;&lt;BR /&gt;
sham1="akram";output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
options mprint;&lt;BR /&gt;
%MACRO Q4;&lt;BR /&gt;
&lt;BR /&gt;
data testing222;&lt;BR /&gt;
set testing22;&lt;BR /&gt;
&lt;B&gt;F8=a;&lt;/B&gt;&lt;BR /&gt;
%do i=1 %to &amp;amp;val;&lt;BR /&gt;
%LET m=%SCAN("&amp;amp;mvar",&amp;amp;i," ") ;&lt;BR /&gt;
%LET k=%SCAN("&amp;amp;mvar1",&amp;amp;i," ") ;&lt;BR /&gt;
F8=TRANWRD(&lt;B&gt;F8&lt;/B&gt;,&amp;amp;k,&amp;amp;m);&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%MEND;&lt;BR /&gt;
&lt;BR /&gt;
%q4&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Tue, 23 Nov 2010 07:12:12 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2010-11-23T07:12:12Z</dc:date>
    <item>
      <title>Problem in using tranwrd function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-in-using-tranwrd-function/m-p/37766#M7520</link>
      <description>/*my problem is that tranwrd function is not working while using in macro with looping and passing macro var..*/&lt;BR /&gt;
/*Problem to resolve*/&lt;BR /&gt;
&lt;BR /&gt;
%let mvar1= rahim1 ramu1 sham1;&lt;BR /&gt;
%let mvar= rahim ramu sham;&lt;BR /&gt;
%let val=3;&lt;BR /&gt;
&lt;BR /&gt;
data testing22;&lt;BR /&gt;
rahim="good";&lt;BR /&gt;
ramu="cool";&lt;BR /&gt;
sham="fine";&lt;BR /&gt;
rahim1="rahim";&lt;BR /&gt;
ramu1="ramu";&lt;BR /&gt;
sham1="akram";&lt;BR /&gt;
a="from rahim";output;&lt;BR /&gt;
a="from ramu";output;&lt;BR /&gt;
a="from akram";output;&lt;BR /&gt;
a="from aram";output;&lt;BR /&gt;
a="from &amp;amp;sham";output;&lt;BR /&gt;
a="from &amp;amp;sham;";output;&lt;BR /&gt;
rahim="good";output;&lt;BR /&gt;
ramu="cool";output;&lt;BR /&gt;
sham="fine";output;&lt;BR /&gt;
rahim1="rahim";output;&lt;BR /&gt;
ramu1="ramu";output;&lt;BR /&gt;
sham1="akram";output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
options mprint mlogic symbolgen;&lt;BR /&gt;
%MACRO Q4;&lt;BR /&gt;
%do i=1 %to &amp;amp;val;&lt;BR /&gt;
%LET m=%SCAN("&amp;amp;mvar",&amp;amp;i," ") ;&lt;BR /&gt;
%LET k=%SCAN("&amp;amp;mvar1",&amp;amp;i," ") ;&lt;BR /&gt;
data testing222;&lt;BR /&gt;
set testing22;&lt;BR /&gt;
F8=TRANWRD(a,trim(&amp;amp;k),trim(&amp;amp;m));* here this function is not working but htere is no error in log as well tried compress and other vars as well but nothing is working is there any other function also to replace the word in a string; &lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%MEND;&lt;BR /&gt;
&lt;BR /&gt;
%q4;&lt;BR /&gt;
&lt;BR /&gt;
/*this is working fine without macro or do loop if we pass the var names manual.*/&lt;BR /&gt;
&lt;BR /&gt;
data testing222;&lt;BR /&gt;
set testing22;&lt;BR /&gt;
F8=TRANWRD(a,rahim1,rahim); &lt;BR /&gt;
run;</description>
      <pubDate>Mon, 22 Nov 2010 07:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-in-using-tranwrd-function/m-p/37766#M7520</guid>
      <dc:creator>SDIWAKER</dc:creator>
      <dc:date>2010-11-22T07:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in using tranwrd function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-in-using-tranwrd-function/m-p/37767#M7521</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
The tranwrd() function works o.k. but the macro might do something different than you think.&lt;BR /&gt;
&lt;BR /&gt;
Run below code and have a look at the log. May be this will give you the explanation what's going on.&lt;BR /&gt;
&lt;BR /&gt;
%LET SHAM=akram;&lt;BR /&gt;
%let mvar1= rahim1 ramu1 sham1;&lt;BR /&gt;
%let mvar= rahim ramu sham;&lt;BR /&gt;
%let val=3;&lt;BR /&gt;
&lt;BR /&gt;
data testing22;&lt;BR /&gt;
&lt;BR /&gt;
  rahim="good";&lt;BR /&gt;
  ramu="cool";&lt;BR /&gt;
  sham="fine";&lt;BR /&gt;
&lt;BR /&gt;
  rahim1="rahim";&lt;BR /&gt;
  ramu1="ramu";&lt;BR /&gt;
  sham1="akram";&lt;BR /&gt;
&lt;BR /&gt;
  a="from rahim";output;&lt;BR /&gt;
  a="from ramu";output;&lt;BR /&gt;
  a="from akram";output;&lt;BR /&gt;
  a="from aram";output;&lt;BR /&gt;
  a="from &amp;amp;sham";output;&lt;BR /&gt;
  a="from &amp;amp;sham;";output;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
options nomprint nomlogic nosymbolgen;&lt;BR /&gt;
%MACRO Q4;&lt;BR /&gt;
  data testing222;&lt;BR /&gt;
    set testing22;&lt;BR /&gt;
    put / "_n_ is" _n_;&lt;BR /&gt;
    %do i=1 %to &amp;amp;val;&lt;BR /&gt;
      %LET m=%SCAN(&amp;amp;mvar,&amp;amp;i," ") ;&lt;BR /&gt;
      %LET k=%SCAN(&amp;amp;mvar1,&amp;amp;i," ") ;&lt;BR /&gt;
      put '&amp;amp;i is ' "&amp;amp;i";&lt;BR /&gt;
      F8=TRANWRD(a,strip(&amp;amp;k),strip(&amp;amp;m));&lt;BR /&gt;
      PUT F8=;&lt;BR /&gt;
    %end;&lt;BR /&gt;
&lt;BR /&gt;
  run;&lt;BR /&gt;
%MEND;&lt;BR /&gt;
&lt;BR /&gt;
%q4;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Mon, 22 Nov 2010 10:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-in-using-tranwrd-function/m-p/37767#M7521</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-11-22T10:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in using tranwrd function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-in-using-tranwrd-function/m-p/37768#M7522</link>
      <description>Thanks for the reply Patrick,&lt;BR /&gt;
&lt;BR /&gt;
I already found the solution, I was using different variable but I should  use the same variable in tranward function so that it should not be overwritten each time with the loop.If we use the same variable it will it will be updated everytime with the loop.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Saurabh Diwaker</description>
      <pubDate>Tue, 23 Nov 2010 05:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-in-using-tranwrd-function/m-p/37768#M7522</guid>
      <dc:creator>SDIWAKER</dc:creator>
      <dc:date>2010-11-23T05:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in using tranwrd function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-in-using-tranwrd-function/m-p/37769#M7523</link>
      <description>Hi.Patrick is right.&lt;BR /&gt;
To avoid to overwrite F8,you need to change the code a little bit to retain the changed value of F8.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let mvar1= rahim1 ramu1 sham1;&lt;BR /&gt;
%let mvar= rahim ramu sham;&lt;BR /&gt;
%let val=3;&lt;BR /&gt;
&lt;BR /&gt;
data testing22;&lt;BR /&gt;
rahim="good";&lt;BR /&gt;
ramu="cool";&lt;BR /&gt;
sham="fine";&lt;BR /&gt;
rahim1="rahim";&lt;BR /&gt;
ramu1="ramu";&lt;BR /&gt;
sham1="akram";&lt;BR /&gt;
a="from rahim";output;&lt;BR /&gt;
a="from ramu";output;&lt;BR /&gt;
a="from akram";output;&lt;BR /&gt;
a="from aram";output;&lt;BR /&gt;
a="from &amp;amp;sham";output;&lt;BR /&gt;
a="from &amp;amp;sham;";output;&lt;BR /&gt;
rahim="good";output;&lt;BR /&gt;
ramu="cool";output;&lt;BR /&gt;
sham="fine";output;&lt;BR /&gt;
rahim1="rahim";output;&lt;BR /&gt;
ramu1="ramu";output;&lt;BR /&gt;
sham1="akram";output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
options mprint;&lt;BR /&gt;
%MACRO Q4;&lt;BR /&gt;
&lt;BR /&gt;
data testing222;&lt;BR /&gt;
set testing22;&lt;BR /&gt;
&lt;B&gt;F8=a;&lt;/B&gt;&lt;BR /&gt;
%do i=1 %to &amp;amp;val;&lt;BR /&gt;
%LET m=%SCAN("&amp;amp;mvar",&amp;amp;i," ") ;&lt;BR /&gt;
%LET k=%SCAN("&amp;amp;mvar1",&amp;amp;i," ") ;&lt;BR /&gt;
F8=TRANWRD(&lt;B&gt;F8&lt;/B&gt;,&amp;amp;k,&amp;amp;m);&lt;BR /&gt;
%end;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%MEND;&lt;BR /&gt;
&lt;BR /&gt;
%q4&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Tue, 23 Nov 2010 07:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-in-using-tranwrd-function/m-p/37769#M7523</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-11-23T07:12:12Z</dc:date>
    </item>
  </channel>
</rss>

