<?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: Character constant truncated to 32767 characters. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Character-constant-truncated-to-32767-characters/m-p/815271#M321799</link>
    <description>Sorry if it has been said many times but the code doesn't work. SAS truncate the base64 text. The code have 17699 characters.</description>
    <pubDate>Thu, 26 May 2022 17:05:55 GMT</pubDate>
    <dc:creator>Sharkman</dc:creator>
    <dc:date>2022-05-26T17:05:55Z</dc:date>
    <item>
      <title>Character constant truncated to 32767 characters.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-constant-truncated-to-32767-characters/m-p/481775#M124696</link>
      <description>&lt;P&gt;Hi!&lt;BR /&gt;&lt;SPAN&gt;Running the code causes a truncation error. Although the input file has a length less than the maximum. This is a test code, but in fact there will come texts of large dimension.&lt;BR /&gt;What could be the reason?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;

%let temp=PGVudE5hbT7QntCR0KnQldCh0KLQktCeINChINCe0JPQoNCQ0J3QmNCn0JXQndCd0J7QmSDQntCi0JLQldCi0KHQotCS0JXQndCd0J7QodCi0KzQriAi0KHQotCg0J7QmNCi0JXQm9Cs0J3QkNCvINCa0J7QnNCf0JDQndCY0K8gItCS0JjQlCI8L2VudE5hbT4=;

		%put temp=&amp;amp;temp;
        %let decodedata =%qsysfunc(inputc(&amp;amp;temp,$base64x32767));
		%put decodedata=&amp;amp;decodedata;
		%let DOCFILE = &amp;amp;TEST/tesе/2.xml;
		FILENAME DOCFILE "&amp;amp;DOCFILE" encoding='wcyrillic' LRECL=32767;

		data _null_;		  
           file DOCFILE LRECL=32767 recfm=f;
           length temp $32767;
           put "&amp;amp;decodedata";		  
        run;

 

%mend test;


%test;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Jul 2018 05:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-constant-truncated-to-32767-characters/m-p/481775#M124696</guid>
      <dc:creator>Liliya95</dc:creator>
      <dc:date>2018-07-27T05:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: Character constant truncated to 32767 characters.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-constant-truncated-to-32767-characters/m-p/481777#M124698</link>
      <description>&lt;P&gt;It has been said many times: don't put data in macro-variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seems to work fine:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.have;
   temp = "PGVudE5hbT7QntCR0KnQldCh0KLQktCeINChINCe0JPQoNCQ0J3QmNCn0JXQndCd0J7QmSDQntCi0JLQldCi0KHQotCS0JXQndCd0J7QodCi0KzQriAi0KHQotCg0J7QmNCi0JXQm9Cs0J3QkNCvINCa0J7QnNCf0JDQndCY0K8gItCS0JjQlCI8L2VudE5hbT4=";
   decodeData = input(temp, $base64x32767.);
run;


filename docfile "&amp;amp;TEST/tesе/2.xml" encoding='wcyrillic' lrecl=32767;

data _null_;
   set have;
   file docfile lrecl=32767 recfm=f;
   put decodedata;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Jul 2018 06:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-constant-truncated-to-32767-characters/m-p/481777#M124698</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-07-27T06:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: Character constant truncated to 32767 characters.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-constant-truncated-to-32767-characters/m-p/815271#M321799</link>
      <description>Sorry if it has been said many times but the code doesn't work. SAS truncate the base64 text. The code have 17699 characters.</description>
      <pubDate>Thu, 26 May 2022 17:05:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-constant-truncated-to-32767-characters/m-p/815271#M321799</guid>
      <dc:creator>Sharkman</dc:creator>
      <dc:date>2022-05-26T17:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: Character constant truncated to 32767 characters.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-constant-truncated-to-32767-characters/m-p/815291#M321800</link>
      <description>&lt;P&gt;What are you trying to do? Your posted code does not make much sense.&amp;nbsp; Why are you defining a variable in the data step that you never use?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why are you trying to work with BASE64 text in macro variables?&lt;/P&gt;
&lt;P&gt;You need to use %QSYSFUNC() but that will add macro quoting to the trailing spaces produced by using an informat with a width that is longer than needed.&lt;/P&gt;
&lt;PRE&gt;1    %let
1  ! temp=PGVudE5hbT7QntCR0KnQldCh0KLQktCeINChINCe0JPQoNCQ0J3QmNCn0JXQndC
1  ! d0J7QmSDQntCi0JLQldCi0KHQotCS0JXQndCd0J7QodCi0KzQriAi0KHQotCg0J7QmNC
1  ! i0JXQm9Cs0J3QkNCvINCa0J7QnNCf0JDQndCY0K8gItCS0JjQlCI8L2VudE5hbT4=;
2
3    %put %length(&amp;amp;temp);
196
4    %let decoded=%qsysfunc(inputc(&amp;amp;temp,$base64x32767.));
5    %put %length(&amp;amp;decoded);
32767

&lt;/PRE&gt;
&lt;P&gt;For an encoded string of 196 bytes the result is a string of 147 bytes.&amp;nbsp; 3*196/4= 147.&lt;/P&gt;
&lt;P&gt;So here is what you need to do.&lt;/P&gt;
&lt;P&gt;1) Use the length of the ENCODED string in the INFORMAT.&amp;nbsp; But this will return a string of that length (so padded with 49 (196-147) extra spaces).&lt;/P&gt;
&lt;P&gt;2) So then use the %QSUBSTR() to remove the extra spaces.&lt;/P&gt;
&lt;PRE&gt;109  %let
109! temp=PGVudE5hbT7QntCR0KnQldCh0KLQktCeINChINCe0JPQoNCQ0J3QmNCn0JXQndC
109! d0J7QmSDQntCi0JLQldCi0KHQotCS0JXQndCd0J7QodCi0KzQriAi0KHQotCg0J7QmNC
109! i0JXQm9Cs0J3QkNCvINCa0J7QnNCf0JDQndCY0K8gItCS0JjQlCI8L2VudE5hbT4=;
110  %let inlength=%length(&amp;amp;temp);
111  %let outlength=%eval((&amp;amp;inlength+3)/4*3);
112  %put &amp;amp;=inlength &amp;amp;=outlength;
INLENGTH=196 OUTLENGTH=147
113  %let
113! decoded=%qsubstr(%qsysfunc(inputc(&amp;amp;temp,$base64x&amp;amp;inlength)),1,&amp;amp;outle
113! ngth);
114  %put &amp;amp;=decoded;
DECODED=&amp;lt;entNam&amp;gt;ÐžÐ‘Ð©Ð•Ð¡Ð¢Ð’Ðž Ð¡ ÐžÐ“Ð&amp;nbsp;Ð&amp;#144;Ð&amp;#157;Ð˜Ð§Ð•Ð&amp;#157;Ð&amp;#157;ÐžÐ™
ÐžÐ¢Ð’Ð•Ð¢Ð¡Ð¢Ð’Ð•Ð&amp;#157;Ð&amp;#157;ÐžÐ¡Ð¢Ð¬Ð® "Ð¡Ð¢Ð&amp;nbsp;ÐžÐ˜Ð¢Ð•Ð›Ð¬Ð&amp;#157;Ð&amp;#144;Ð¯
ÐšÐžÐœÐŸÐ&amp;#144;Ð&amp;#157;Ð˜Ð¯ "Ð’Ð˜Ð”"&amp;lt;/entNam&amp;gt;
115  %put %length(&amp;amp;decoded);
147
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 18:11:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-constant-truncated-to-32767-characters/m-p/815291#M321800</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-26T18:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Character constant truncated to 32767 characters.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-constant-truncated-to-32767-characters/m-p/815297#M321803</link>
      <description>&lt;P&gt;Note also that if the encoded string is not an exact multiple of 4 bytes long then you need to append equal signs until it is so that the BASE64 string has the right number of bits to be split back into base256 strings.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;217  data test;
218    x='AB';
219    encode = put(x,$base64x4.);
220    put encode=;
221  run;

encode=QUI=
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


222
223
224  %let coded=QUI;
225  %let raw_length=%length(&amp;amp;coded);
226  %let actual_length=%eval((&amp;amp;raw_length+3)/4*4);
227  %put &amp;amp;=raw_length &amp;amp;=actual_length ;
RAW_LENGTH=3 ACTUAL_LENGTH=4
228  %put %sysfunc(inputc(&amp;amp;coded,$base64x&amp;amp;raw_length));

229  %put %sysfunc(inputc(&amp;amp;coded,$base64x&amp;amp;actual_length));

230  %put %sysfunc(inputc(&amp;amp;coded===,$base64x&amp;amp;actual_length));
AB
&lt;/PRE&gt;
&lt;P&gt;So make sure to figure out the right length to use and to append some equal signs.&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 18:21:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-constant-truncated-to-32767-characters/m-p/815297#M321803</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-26T18:21:03Z</dc:date>
    </item>
  </channel>
</rss>

