<?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 Transwrd matching everything in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Transwrd-matching-everything/m-p/521241#M4178</link>
    <description>&lt;P&gt;Hi I have a&amp;nbsp; macro variable called list when I used tranwrd it matches everything&lt;BR /&gt;%let list=apple ball cats bapplee;&lt;BR /&gt;%let i=1 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let dependent=%scan(&amp;amp;list,&amp;amp;i," ");/* list of dependent variable*/&lt;BR /&gt;%let independent = %sysfunc(tranwrd(&amp;amp;list, &amp;amp;dependent.,%str()));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%put &amp;amp;dependent;&lt;BR /&gt;%put &amp;amp;independent;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result I am getting is&amp;nbsp;ball cats b e&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result I want is ball cats bapplee&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I get the expected result?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Shone&lt;/P&gt;</description>
    <pubDate>Thu, 13 Dec 2018 18:40:49 GMT</pubDate>
    <dc:creator>Shone</dc:creator>
    <dc:date>2018-12-13T18:40:49Z</dc:date>
    <item>
      <title>Transwrd matching everything</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transwrd-matching-everything/m-p/521241#M4178</link>
      <description>&lt;P&gt;Hi I have a&amp;nbsp; macro variable called list when I used tranwrd it matches everything&lt;BR /&gt;%let list=apple ball cats bapplee;&lt;BR /&gt;%let i=1 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let dependent=%scan(&amp;amp;list,&amp;amp;i," ");/* list of dependent variable*/&lt;BR /&gt;%let independent = %sysfunc(tranwrd(&amp;amp;list, &amp;amp;dependent.,%str()));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%put &amp;amp;dependent;&lt;BR /&gt;%put &amp;amp;independent;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result I am getting is&amp;nbsp;ball cats b e&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Result I want is ball cats bapplee&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I get the expected result?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Shone&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 18:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transwrd-matching-everything/m-p/521241#M4178</guid>
      <dc:creator>Shone</dc:creator>
      <dc:date>2018-12-13T18:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Transwrd matching everything</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Transwrd-matching-everything/m-p/521275#M4179</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the&amp;nbsp;&lt;A title="TRANWRD Function" href="https://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0pgemqcslm9uen1tvr5gcrusgrw.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;documentation&lt;/A&gt;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;H3 class="xis-title"&gt;The Basics&lt;/H3&gt;
&lt;DIV id="n0e89pq2ulc6p1n1q2bq6b3jtb6g" class="xis-topicContent"&gt;
&lt;DIV id="n0pf2uqx3srktwn0zr1yafcmfunv" class="xis-paragraph"&gt;The TRANWRD function copies the value in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;source&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to the result string while searching for all non-overlapping substrings in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;source&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;that are equal to the value in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;target&lt;/SPAN&gt;. Each of these substrings is omitted from the result and the value of&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;replacement&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is copied in its place. The TRANWRD function does not remove trailing blanks in the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;target&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;string or the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;replacement&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;string.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;DIV id="n0e89pq2ulc6p1n1q2bq6b3jtb6g" class="xis-topicContent"&gt;
&lt;DIV class="xis-paragraph"&gt;A good place to start is to first remove complexity by removing all the macro references e.g.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;
	x=tranwrd("apple ball cats bapplee","apple","xxx") ;
	put x= ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
When you run this then you can&amp;nbsp;understand what TRANWRD is doing:&lt;/DIV&gt;
&lt;DIV class="xis-paragraph"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;149  data _null_ ;
150      x=tranwrd("apple ball cats bapplee","apple","xxx") ;
151      put x= ;
152  run ;

x=xxx ball cats bxxxe
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
As you can see every&amp;nbsp;occurrence of "apple" is replaced by "xxx" which is why "bapplee" is transformed to bxxxe&lt;BR /&gt;&lt;BR /&gt;So how do you get the result you are looking for, well that's where it gets a little tricky as I can't be sure of your data, but one option could be to add a space after the target:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;218  data _null_ ;
219      x=tranwrd("apple ball cats bapplee","apple "," ") ;
220      put x= ;
221  run ;

x=ball cats bapplee
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
But that would depend on your data and what you want to achieve&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I hope this helps&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 13 Dec 2018 20:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Transwrd-matching-everything/m-p/521275#M4179</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2018-12-13T20:12:37Z</dc:date>
    </item>
  </channel>
</rss>

