<?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 Why the TRANSLATE FUNCTION translate incorrectly? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-the-TRANSLATE-FUNCTION-translate-incorrectly/m-p/181926#M34684</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone:&lt;/P&gt;&lt;P&gt;I've written the code as below and I expected the result in log was '123456789101112;223456789101112' but what I get is '323;223'. Would anyone tell me why the TANSLATE did not work as is described and how to approach what I want? Appreciate any help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;length tran $50.;&lt;/P&gt;&lt;P&gt;tran=translate('yhp;qly','123456789101112','yhp','223456789101112','qly');&lt;/P&gt;&lt;P&gt;put tran;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Qinly&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Jan 2015 09:11:45 GMT</pubDate>
    <dc:creator>LinyuanQin</dc:creator>
    <dc:date>2015-01-14T09:11:45Z</dc:date>
    <item>
      <title>Why the TRANSLATE FUNCTION translate incorrectly?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-TRANSLATE-FUNCTION-translate-incorrectly/m-p/181926#M34684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone:&lt;/P&gt;&lt;P&gt;I've written the code as below and I expected the result in log was '123456789101112;223456789101112' but what I get is '323;223'. Would anyone tell me why the TANSLATE did not work as is described and how to approach what I want? Appreciate any help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;length tran $50.;&lt;/P&gt;&lt;P&gt;tran=translate('yhp;qly','123456789101112','yhp','223456789101112','qly');&lt;/P&gt;&lt;P&gt;put tran;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Qinly&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jan 2015 09:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-TRANSLATE-FUNCTION-translate-incorrectly/m-p/181926#M34684</guid>
      <dc:creator>LinyuanQin</dc:creator>
      <dc:date>2015-01-14T09:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why the TRANSLATE FUNCTION translate incorrectly?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-TRANSLATE-FUNCTION-translate-incorrectly/m-p/181927#M34685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check out the help documentation for the function: &lt;A class="active_link" href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000215153.htm"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000215153.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Firstly the details section explains why the length is not as expected - it sets the new variable to be as long as the first parameter you pass in, so yhp;qly = length 7, output length is going to be 7, not all those other characters.&lt;/P&gt;&lt;P&gt;Also, you may want to split that statement up:&lt;/P&gt;&lt;P&gt;data tmp;&lt;/P&gt;&lt;P&gt;length tran $50.;&lt;/P&gt;&lt;P&gt;tran=translate('yhp;qly','123456789101112','yhp');&lt;BR /&gt;tran=translate(tran,'223456789101112','qly');&lt;BR /&gt;put tran;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or, use the tranwrd function just to replace things.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Jan 2015 09:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-TRANSLATE-FUNCTION-translate-incorrectly/m-p/181927#M34685</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-01-14T09:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why the TRANSLATE FUNCTION translate incorrectly?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-the-TRANSLATE-FUNCTION-translate-incorrectly/m-p/181928#M34686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks like it is doing what you asked.&amp;nbsp; TRANSLATE works on characters, not strings.&lt;/P&gt;&lt;P&gt;You told it to take the string&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 12pt;"&gt;'yhp;qly'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;And make these letter transformations:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 12pt;"&gt;y -&amp;gt; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 12pt;"&gt;h -&amp;gt; 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 12pt;"&gt;p -&amp;gt; 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 12pt;"&gt;q -&amp;gt; 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 12pt;"&gt;l -&amp;gt; 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 12pt;"&gt;y -&amp;gt; 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Note that have two different targets for the letter y so the last one won and you ended up with:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 12pt;"&gt;'323;223'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;Perhaps you wanted to use TRANWRD() or TRANSTRN() function instead?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff; font-size: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Jan 2015 00:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-the-TRANSLATE-FUNCTION-translate-incorrectly/m-p/181928#M34686</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-01-16T00:37:23Z</dc:date>
    </item>
  </channel>
</rss>

