<?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: TRANSLATE() function became /... crazy :-( . in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930624#M366142</link>
    <description>Thanks, it works. I didn't know this function exists... of course there are so much functions in the SAS that somebody can't embrance most of them (especially when is focussing to analytics and mining -e.g.). MBK</description>
    <pubDate>Mon, 03 Jun 2024 16:25:47 GMT</pubDate>
    <dc:creator>MBKsk</dc:creator>
    <dc:date>2024-06-03T16:25:47Z</dc:date>
    <item>
      <title>TRANSLATE() function became /... crazy :-( .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930601#M366135</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm fighting with a translate() function in my new job.&lt;/P&gt;&lt;P&gt;I have my 'old faithful' code fragment to remove diacritics (accented characters) which worked fine (both: in datastep and proc sql) -till current job:&lt;/P&gt;&lt;P&gt;TRANSLATE(FirstNAME, "aaccdeeillnnoorrsstuyzz", "áäčćďéěíĺľňńóôŕřšśťúýžź")&lt;/P&gt;&lt;P&gt;&amp;nbsp;+ I tried to replace " with apostrophs &amp;gt;&amp;gt;&amp;gt; no!&lt;/P&gt;&lt;P&gt;&amp;nbsp;+ I tried to change obly one character (e.g. á to a) - it worked well&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;+ but when I extend &amp;lt;StringFROM&amp;gt; and &amp;lt;StringTO&amp;gt; to very small set of characters (fom 'áíšžň' to 'aiszn') &amp;gt;&amp;gt; translate() started to mix the characters: ..&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; + Adamík&amp;nbsp; =&amp;gt;&amp;gt;&amp;gt; Adami k&amp;nbsp; &amp;nbsp;... error: add space after correct change&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; + Arpáš =&amp;gt;&amp;gt;&amp;gt; Arpi �&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... change á to i instead of a + strange char inst. "s"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; + Badáň =&amp;gt;&amp;gt;&amp;gt; Badi ň&amp;nbsp; &amp;nbsp; ... same "a" + ignore ň from list&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; + Ažimov =&amp;gt;&amp;gt;&amp;gt; Ažimov&amp;nbsp; &amp;nbsp;... ignore ž&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bonus: I have another 'shape' to remove strange chars from a name and it seems works &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; ...&amp;nbsp;(all are changed to a space which is further celaning by COMPBL() &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;COMPBL(translate(FirstNAME, "&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;", "0123456789/\:;|{}[]()!@#$%^&amp;amp;*_.,-")) as MyLoveNAME,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have somebody an idea where is it screwed?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: I hacked it by this ugly patch ...&lt;/P&gt;&lt;P&gt;tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(tranwrd(&lt;BR /&gt;&amp;nbsp; &amp;nbsp;lowcase(cli.FirstNAME),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'á', 'a'), 'ä', 'a'), 'č', 'c'), 'ď', 'd'), 'é', 'e'), 'ě', 'e'), 'í', 'i'), 'ĺ', 'l'), 'ľ', 'l'), 'ň', 'n'), 'ó', 'o'), 'ô', 'o'), 'ŕ', 'r'), 'ř', 'r'), 'š', 's'), 'ť', 't'), 'ú', 'u'), 'ý', 'y'), 'ž', 'z') as NameNoDIA,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; ...but it makes me sick &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; and -truly: i'm surprising it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-thx- Martin&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 12:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930601#M366135</guid>
      <dc:creator>MBKsk</dc:creator>
      <dc:date>2024-06-03T12:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: TRANSLATE() function became /... crazy :-( .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930602#M366136</link>
      <description>&lt;P&gt;Convert characters with diacritical marks to their equivalent without the diacritical mark via the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/nlsref/p078j5y1bbc9xfn1scp11kw3nmnt.htm" target="_self"&gt;BASECHAR function&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fake;
     text='ÇñaıŁá';
     text2=basechar(text);
run;
&lt;/CODE&gt;&lt;/PRE&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 13:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930602#M366136</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-06-03T13:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: TRANSLATE() function became /... crazy :-( .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930604#M366137</link>
      <description>&lt;P&gt;Check the encoding of the file.&lt;/P&gt;
&lt;P&gt;Some of this sounds like a file that previously used high order ASCII characters, those with numeric representation over 127 to hold the diacritics but now may have UNICODE characters, which are different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "add a space" is actually a clue as ASCII characters take one-byte for storage but UNICODE starts at two bytes and may take as many as 4 in some languages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 13:36:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930604#M366137</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-03T13:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: TRANSLATE() function became /... crazy :-( .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930624#M366142</link>
      <description>Thanks, it works. I didn't know this function exists... of course there are so much functions in the SAS that somebody can't embrance most of them (especially when is focussing to analytics and mining -e.g.). MBK</description>
      <pubDate>Mon, 03 Jun 2024 16:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930624#M366142</guid>
      <dc:creator>MBKsk</dc:creator>
      <dc:date>2024-06-03T16:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: TRANSLATE() function became /... crazy :-( .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930626#M366143</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466388"&gt;@MBKsk&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Glad to see that Paige Miller's solution worked for you. Then it would be fair and help later readers if you marked his helpful reply as the accepted solution, not your own "thank you" post. Could you please change that? It's very easy: Select his post&amp;nbsp;as the solution after clicking&amp;nbsp;"Not the Solution" in the option menu (see icon below) of the current solution.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="show_option_menu.png" style="width: 155px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96924i64C92A8A112C7DC5/image-size/large?v=v2&amp;amp;px=999" role="button" title="show_option_menu.png" alt="show_option_menu.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 16:30:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930626#M366143</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-06-03T16:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: TRANSLATE() function became /... crazy :-( .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930627#M366144</link>
      <description>&lt;P&gt;Thanks to describe why it needn't works anytime (which I a little bit understand at least &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; )&lt;/P&gt;&lt;P&gt;...but - next it a little overolad my weight category&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;...I've tried to see the coding of my source tab (proc contents) but I realized "default" as result :-'&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;...and I didn't suceed to find a structure of the UNICODE character (for example this á with space as bonus)&lt;/P&gt;&lt;P&gt;Thank you - it is interesting to know some background.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Jun 2024 16:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930627#M366144</guid>
      <dc:creator>MBKsk</dc:creator>
      <dc:date>2024-06-03T16:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: TRANSLATE() function became /... crazy :-( .</title>
      <link>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930750#M366179</link>
      <description>&lt;P&gt;TRANSLATE() works on single bytes.&amp;nbsp; If you are using ENCODING=UTF-8 then some of the "characters" in your string will be multiple bytes long.&amp;nbsp; That is going to cause all kinds of crazy to happen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider just two of those characters.&amp;nbsp; Let's make a little test, Let's but the FROM and TO strings into their own variables so we can get a look at what they contain.&lt;/P&gt;
&lt;PRE&gt; 73         data test;
 74           String =  "XáäčY";
 75           To = "aa" ;
 76           From = "áä" ;
 77           Want = String;
 78           Want = TRANSLATE(string,to,from);
 79           put (string -- want) (=$quote.);
 80           put (string -- want) (=$hex.);
 81         run;
 
 String="XáäčY" To="aa" From="áä" Want="Xaaa čY"
 String=58C3A1C3A4C48D59 To=6161 From=C3A1C3A4 Want=5861616120C48D59
 NOTE: The data set WORK.TEST has 1 observations and 4 variables.&lt;/PRE&gt;
&lt;P&gt;Notice that the FROM string has 4 bytes and the TO string only has 2 bytes.&amp;nbsp; TRANSLATE() will pad the TO string with spaces ('20'x) to make them the same length.&amp;nbsp; So you are telling TRANSLATE to perform the following replacements:&lt;/P&gt;
&lt;PRE&gt;To=6161 From=C3A1C3A4
C3 -&amp;gt; 61
A1 -&amp;gt; 61
C3 -&amp;gt; 20
A4 -&amp;gt; 20&lt;/PRE&gt;
&lt;P&gt;Notice that you gave conflicting instructions on how to translate the 'C3'x bytes.&amp;nbsp; First said make it an a and then you said make it a space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's look at the result and see which one it decided to map that byte to.&lt;/P&gt;
&lt;PRE&gt;String=58C3A1C3A4C48D59 
Want  =5861616120C48D59&lt;/PRE&gt;
&lt;P&gt;So C3 was mapped to 61 (the letter a) and&amp;nbsp; A1 was also mapped to the letter a.&lt;/P&gt;
&lt;P&gt;And A4 was mapped to a space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So TRANSLATE() uses the FIRST value you ask it to translate into when you have the same byte multiple times in the FROM list of bytes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to translate characters instead of bytes then use the KTRANSLATE() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;KTRANSLATE(FirstNAME, "aaccdeeillnnoorrsstuyzz", "áäčćďéěíĺľňńóôŕřšśťúýžź")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If we use the same test program with KTRANSLATE() instead this is the result:&lt;/P&gt;
&lt;PRE&gt; String="XáäčY" To="aa" From="áä" Want="XaačY"
 String=58C3A1C3A4C48D59 To=6161 From=C3A1C3A4 Want=586161C48D592020&lt;/PRE&gt;
&lt;P&gt;Notice the two extra spaces on the end of WANT.&amp;nbsp; That is because WANT was defined long enough to store STRING.&amp;nbsp; And after replacing two characters that used 2 bytes each with a character that needs only one byte the resulting string is 2 bytes shorter.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2024 01:51:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/TRANSLATE-function-became-crazy/m-p/930750#M366179</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-04T01:51:33Z</dc:date>
    </item>
  </channel>
</rss>

