<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475958#M122436</link>
    <description>&lt;P&gt;It's work? but I have to&amp;nbsp;get text from file and&amp;nbsp;change all&amp;nbsp; ". But when&amp;nbsp;insert text, I have error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Jul 2018 11:30:08 GMT</pubDate>
    <dc:creator>Liliya95</dc:creator>
    <dc:date>2018-07-06T11:30:08Z</dc:date>
    <item>
      <title>translate function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475951#M122430</link>
      <description>&lt;P&gt;I have text from file and I need to change some char.&lt;/P&gt;
&lt;P&gt;but w&lt;SPAN&gt;hen I execute the code with a variable, the letters turn into something else. But if you insert the text manually, everything works correctly&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to &amp;amp;pfrcnt; 
%let tmp2=&amp;amp;decodedata; 
data tmp2; 
tmp2=%sysfunc(translate(&amp;amp;tmp2,'&amp;amp;','"')); 
run; 
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log&lt;/P&gt;
&lt;PRE&gt; tmp2 before translate 
&amp;lt;yearPeriodbeg="01.01.2016" end="31.12.2016" /&amp;gt; 
tmp2 after translate and error:
 tmp2= РРРР W WРРРР S SРРРР H РРРРРР СЃЃРЏ ЏµРЅЏµРР°Џ°РРЏ‡Џ°РРЏ°Џ·ЏµЏСЏ°РІРЏ°РЏrЏµРЅЏµР&amp;amp;ЏРЏ°РРРЏ°РРРЅЏ° 
ERROR: The value 'Р'nis not a valid SAS name. &lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;when I insert the text manually&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp;
	tmp=%sysfunc(translate('&amp;lt;yearPeriod beg="01.01.2016" end="31.12.2016"  /&amp;gt;','&amp;amp;','"'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;all is well&lt;/P&gt;
&lt;PRE&gt;&amp;lt;yearPeriod beg=&amp;amp;01.01.2016&amp;amp; end=&amp;amp;31.12.2016&amp;amp;&amp;nbsp; /&amp;gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 19:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475951#M122430</guid>
      <dc:creator>Liliya95</dc:creator>
      <dc:date>2018-07-06T19:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: translate function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475955#M122433</link>
      <description>&lt;P&gt;Sorry, but the code is unreadable.&lt;/P&gt;
&lt;P&gt;You don't need %sysfunc when using translate in a data-step and you don't quote strings in macro-statements.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 11:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475955#M122433</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-07-06T11:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: translate function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475957#M122435</link>
      <description>&lt;P&gt;Text in a file is data, and should be treated as such. Therefore you DO NOT keep it in macro variables, which are meant to hold code parts. The macro preprocessor is a code generating language, not more or less.&lt;/P&gt;
&lt;P&gt;So&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input tmp2 $80.;
datalines4;
&amp;lt;yearPeriodbeg="01.01.2016" end="31.12.2016"
;;;;
run;

data want;
set have;
tmp2 = translate(tmp2,'&amp;amp;','"');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jul 2018 11:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475957#M122435</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-06T11:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: translate function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475958#M122436</link>
      <description>&lt;P&gt;It's work? but I have to&amp;nbsp;get text from file and&amp;nbsp;change all&amp;nbsp; ". But when&amp;nbsp;insert text, I have error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 11:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475958#M122436</guid>
      <dc:creator>Liliya95</dc:creator>
      <dc:date>2018-07-06T11:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: translate function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475959#M122437</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/166024"&gt;@Liliya95&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It's work? but I have to&amp;nbsp;get text from file and&amp;nbsp;change all&amp;nbsp; ". But when&amp;nbsp;insert text, I have error&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Of course it does work. Copy my code and run it.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 11:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475959#M122437</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-06T11:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: translate function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475960#M122438</link>
      <description>&lt;P&gt;&lt;SPAN&gt;sorry put a question mark by mistake.&lt;BR /&gt;But I can not write the text using the dataline.&lt;BR /&gt;There is a file, it is disassembled and a part is written in a variable&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;all code:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;......
%do i=1 %to &amp;amp;count; 
    
        %let data =%sysfunc(inputc("&amp;amp;&amp;amp;pfrbase64code&amp;amp;i", $base64x32767));
		%let FILE = &amp;amp;path/file_&amp;amp;i..xml;
        FILENAME FILE "&amp;amp;FILE" encoding='wcyrillic' LRECL=32767;

	data tmp2;

		tmp2=translate(&amp;amp;tmp2,'&amp;amp;','"');
	run;

     data _null_;
          
          fileFILE LRECL=32767;
          length tm $32767;
          put "&amp;amp;tmp2";

        run;


 %end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jul 2018 11:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475960#M122438</guid>
      <dc:creator>Liliya95</dc:creator>
      <dc:date>2018-07-06T11:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: translate function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475962#M122440</link>
      <description>&lt;P&gt;So you want to replace a character in a file?&lt;/P&gt;
&lt;P&gt;Start with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename in "path_to_file" lrecl=32767;
filename out "path_to outfile" lrecl=32767;

data _null_;
infile in truncover;
file out;
input tmp $char32767.;
tmp = translate(tmp,'&amp;amp;','"');
put tmp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The only other (implicit) change that such a program does: it removes trailing blanks in lines, which should not be a problem with markup text.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 11:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/475962#M122440</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-07-06T11:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: translate function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/476119#M122489</link>
      <description>&lt;P&gt;Your first macro loop around a data step is just creating&amp;nbsp;the same dataset with one observation and one variable over and over again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the source of the actual data?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 19:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/476119#M122489</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-06T19:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: translate function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/476130#M122491</link>
      <description>&lt;P&gt;You need to explain what you are actually trying to do.&lt;/P&gt;
&lt;P&gt;Your posted code does not make much sense.&lt;/P&gt;
&lt;P&gt;Just read that code line by line and ask yourself what each line is doing.&lt;/P&gt;
&lt;P&gt;First you have wrapped the whole thing into a macro %DO loop. So I assume there is also a macro definition that this is part of.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro xxx ;
%do i=1 %to &amp;amp;count; 
 ...
%end;
%mend xxx;
%xxx;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's ignore that as irrelevant to your question.&lt;/P&gt;
&lt;P&gt;So first you run this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let data =%sysfunc(inputc("&amp;amp;&amp;amp;pfrbase64code&amp;amp;i", $base64x32767));
%let FILE = &amp;amp;path/file_&amp;amp;i..xml;
FILENAME FILE "&amp;amp;FILE" encoding='wcyrillic' LRECL=32767;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not sure what the purpose of the first line is as it does not appear to be used any where.&amp;nbsp; The other two lines look like an attempt to define a fileref name FILE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you create this dataset named TMP2 by using a macro variable named TMP2 that has not been referenced before.&lt;/P&gt;
&lt;P&gt;Not sure what purpose this step serves as the generated dataset is never used for anything.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp2;
  tmp2=translate(&amp;amp;tmp2,'&amp;amp;','"');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You then run another separate data step where it looks like your intent is to write to the fileref defined before.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file FILE LRECL=32767;
  length tm $32767;
  put "&amp;amp;tmp2";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But all you are trying to write is the unmodifed content of the previous read macro variable TMP2.&lt;/P&gt;
&lt;P&gt;So again what was the purpose of the first data step with its TRANSLATE() function call?&lt;/P&gt;
&lt;P&gt;You also define but never use a variable named TM.&amp;nbsp; Why is that line there?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 19:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/translate-function/m-p/476130#M122491</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-06T19:54:21Z</dc:date>
    </item>
  </channel>
</rss>

