<?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: ERROR: String data, right-truncated in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851995#M336774</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/232758"&gt;@aloou&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;i tried this and it works perfectly , however in my code it does not do well.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which why you were asked to post the actual code, not a snippet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your strings have some non 7bit ASCII characters I suspect that you might be seeing the impact of transcoding the strings changing the length (number of bytes) needed to store the characters.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;777  data test;
778    length x y $200 ;
779    x = '-10% à -5%';
780    y = kcvt(x,'wlatin1','utf-8');
781    lenx=length(x);
782    leny=length(y);
783    put lenx= leny=;
784  run;

lenx=10 leny=11
&lt;/PRE&gt;
&lt;P&gt;Just making sure the target variable is defined long enough to store the full length of the string being placed into it should eliminate the truncation error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure the truncation is actual for this variable and not some other variable?&lt;/P&gt;</description>
    <pubDate>Tue, 03 Jan 2023 16:18:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-01-03T16:18:05Z</dc:date>
    <item>
      <title>ERROR: String data, right-truncated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851849#M336728</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;i just tried to create a table, i have a case when clause that generates an error.&lt;/P&gt;
&lt;P&gt;(case&lt;BR /&gt;when t1.code_chiffre_affaire = 1 then '&amp;lt;-10%'&lt;BR /&gt;when t1.code_chiffre_affaire = 2 then '-10% à -5%'&lt;BR /&gt;when t1.code_chiffre_affaire = 3 then '-5% à 0%'&lt;BR /&gt;when t1.code_chiffre_affaire = 4 then '0% à +5%'&lt;BR /&gt;when t1.code_chiffre_affaire = 5 then '+5% à +10%'&lt;BR /&gt;when t1.code_chiffre_affaire = 6 then '&amp;gt;+10%' end)&lt;BR /&gt;as tranche_var_chiff_aff&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the error :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;ERROR: String data, right-truncated TRANCHE_VAR_CHIFF_AFF&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 17:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851849#M336728</guid>
      <dc:creator>aloou</dc:creator>
      <dc:date>2023-01-02T17:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: String data, right-truncated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851855#M336729</link>
      <description>&lt;P&gt;Please show us the ENTIRE log for this PROC SQL, with nothing chopped out; we need to see every single character and every single line in the log for this PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please copy and paste the log into the window that appears when you click on the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66123iA4EF494F9CA0F6EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" alt="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 18:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851855#M336729</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-01-02T18:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: String data, right-truncated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851864#M336731</link>
      <description>&lt;P&gt;Try explicitly setting the column length like so:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;(case
when t1.code_chiffre_affaire = 1 then '&amp;lt;-10%'
when t1.code_chiffre_affaire = 2 then '-10% à -5%'
when t1.code_chiffre_affaire = 3 then '-5% à 0%'
when t1.code_chiffre_affaire = 4 then '0% à +5%'
when t1.code_chiffre_affaire = 5 then '+5% à +10%'
when t1.code_chiffre_affaire = 6 then '&amp;gt;+10%' end)
as tranche_var_chiff_aff length = 20&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Jan 2023 20:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851864#M336731</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-01-02T20:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: String data, right-truncated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851883#M336736</link>
      <description>&lt;P&gt;I can't replicate this error.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please execute below in your environment. If that doesn't replicate the error then please post more of your code and SAS log.&lt;/P&gt;
&lt;P&gt;Also: You should always finish a CASE statement with an ELSE case to ensure your conditions are exhaustive.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do code_chiffre_affaire=1 to 7;
    output;
  end;
run;

proc sql;
  select 
    (case
    when t1.code_chiffre_affaire = 1 then '&amp;lt;-10%'
    when t1.code_chiffre_affaire = 2 then '-10% à -5%'
    when t1.code_chiffre_affaire = 3 then '-5% à 0%'
    when t1.code_chiffre_affaire = 4 then '0% à +5%'
    when t1.code_chiffre_affaire = 5 then '+5% à +10%'
    when t1.code_chiffre_affaire = 6 then '&amp;gt;+10%' end)
    as tranche_var_chiff_aff
  from have t1
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Jan 2023 03:31:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851883#M336736</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-03T03:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: String data, right-truncated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851989#M336771</link>
      <description>i tried this and it works perfectly , however in my code it does not do well.</description>
      <pubDate>Tue, 03 Jan 2023 15:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851989#M336771</guid>
      <dc:creator>aloou</dc:creator>
      <dc:date>2023-01-03T15:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: String data, right-truncated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851995#M336774</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/232758"&gt;@aloou&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;i tried this and it works perfectly , however in my code it does not do well.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which why you were asked to post the actual code, not a snippet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your strings have some non 7bit ASCII characters I suspect that you might be seeing the impact of transcoding the strings changing the length (number of bytes) needed to store the characters.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;777  data test;
778    length x y $200 ;
779    x = '-10% à -5%';
780    y = kcvt(x,'wlatin1','utf-8');
781    lenx=length(x);
782    leny=length(y);
783    put lenx= leny=;
784  run;

lenx=10 leny=11
&lt;/PRE&gt;
&lt;P&gt;Just making sure the target variable is defined long enough to store the full length of the string being placed into it should eliminate the truncation error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure the truncation is actual for this variable and not some other variable?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 16:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/851995#M336774</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-01-03T16:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: String data, right-truncated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/852000#M336778</link>
      <description>here i posted the script and logs</description>
      <pubDate>Tue, 03 Jan 2023 16:49:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/852000#M336778</guid>
      <dc:creator>aloou</dc:creator>
      <dc:date>2023-01-03T16:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: String data, right-truncated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/852034#M336795</link>
      <description>&lt;P&gt;You are using SAS Viya and PROC CAS which many responders don't have access to. You might get a quicker response from SAS Tech Support.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 22:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/852034#M336795</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-01-03T22:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: String data, right-truncated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/852063#M336819</link>
      <description>&lt;P&gt;Based on some Internet research the Error is most likely due to SAS not creating variable&amp;nbsp;&lt;EM&gt;tranche_var_chiff_aff&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;with a sufficient length. It's certainly worth to contact SAS TechSupport directly. Make sure you provide them with the Viya version you're using and your site number (proc setinit;run; will give you this information).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like so many of us I also don't have access to a Viya playpen environment so can't test.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try to use an explicit cast() statement to define the variable explicitly with a sufficient length.&amp;nbsp;Below works with FedSQL under SAS9.4 M7.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do code_chiffre_affaire=1 to 7;
    output;
  end;
run;

proc datasets lib=work nolist nowarn;
  delete test;
quit;

proc fedsql;
  create table work.test as
  select 
    cast(
      (case
        when t1.code_chiffre_affaire = 1 then '&amp;lt;-10%'
        when t1.code_chiffre_affaire = 2 then '-10% à -5%'
        when t1.code_chiffre_affaire = 3 then '-5% à 0%'
        when t1.code_chiffre_affaire = 4 then '0% à +5%'
        when t1.code_chiffre_affaire = 5 then '+5% à +10%'
        when t1.code_chiffre_affaire = 6 then '&amp;gt;+10%' end)
        as varchar(20))
      as tranche_var_chiff_aff
  from have t1
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2023 01:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-String-data-right-truncated/m-p/852063#M336819</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-04T01:17:34Z</dc:date>
    </item>
  </channel>
</rss>

