<?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: length of  character variable in SAS/IML; in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/length-of-character-variable-in-SAS-IML/m-p/789741#M5748</link>
    <description>&lt;P&gt;The issue you are encountering is because certain Base SAS concatenation functions (CAT, CATS, CATT, CATX, etc) set the length of an uninitialized variable to 200. If the return value from the function exceeds that length, you will get a warning, such as in the following DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* some concatenation functions implicitly set the 
   length that for an unitialized LHS variable to 200 */
data _null_;
s = catt("A", "B");     /* implicitly sets LENGTH s $200 */

/* make a long string */
x1 = "1234567890123456789012345678901234567890";  /* 40 char */
x2 = x1; x3 = x1; x4 = x1; x5 = x1; x6 = x1;
s2 = catt(x1, x2, x3, x4, x5, x6);    /* WARNING: RHS does not fit into length=200 */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log displays&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WARNING: In a call to the CATT function, the buffer allocated
         for the result was not long enough to contain the
         concatenation of all the arguments. The correct result
         would contain 240 characters, but the actual result
         might either be truncated to 200 character(s) or be
         completely blank, depending on the calling
         environment. The following note indicates the
         left-most argument that caused truncation.
&lt;/PRE&gt;
&lt;P&gt;If you call one of the "CAT" functions from IML, you will get similar behavior and the WARNING is coming from the Base function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the DATA step, you work around this issue by using the LENGTH statement to allocate the left-hand side variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length s2 $240;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because IML uses dynamic allocation for each statement, there is no LENGTH statement in the IML language. Instead, I think you can work around this issue in IML by using the built-in '+' operator, which is the IML version of the concatenation functions. You can combine the '+' operator with the STRIP or TRIM functions if you need to remove blanks.&amp;nbsp; The following IML program reads in long strings and uses the '+' operator to concatenate them. You can see that the resulting strings are longer than 200 characters:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
/* make long strings */
length s1 s2 $240 x1-x6 $50;
x1 = "1234567890123456789012345678901234567890";  /* 40 char */
x2 = x1; x3 = x1; x4 = x1; x5 = x1; x6 = x1; 
s1 = catt(x1, x2, x3, x4, x5, x6);
s2 = s1;
run;


proc iml;
use Have;
read all var {s1 s2 x1 x2 x3 x4 x5 x6};
close;

s = trim(x1) + trim(x2) + trim(x3) + 
    trim(x4) + trim(x5) + trim(x6);
nlen = nleng(s);
len = length(s);
print nlen len;

s = trim(s1) + trim(s2);
nlen = nleng(s);
len = length(s);
print nlen len;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jan 2022 15:02:34 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2022-01-12T15:02:34Z</dc:date>
    <item>
      <title>length of  character variable in SAS/IML;</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/length-of-character-variable-in-SAS-IML/m-p/789721#M5747</link>
      <description>&lt;P&gt;I am using the following code&lt;/P&gt;
&lt;P&gt;s_last=catt(substr(s_last,1,length(s_last)-ns),pxs[locx]); &lt;/P&gt;
&lt;P&gt;to add some character string to the original one.&lt;/P&gt;
&lt;P&gt;This working in cycle and when the size of string reaches 255 process stops, saying the IML procedure can't allocate buffer longer than 256.&lt;/P&gt;
&lt;P&gt;At the same time, when I use the sample code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;test=rowcat(T(p7s));&lt;BR /&gt;show test;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can see&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE summary="Page Layout" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;PRE class="batch"&gt;test      1 row       1 col     (character, size 35280)  &lt;/PRE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;So, My question is, how to make use of&amp;nbsp; long&amp;nbsp; character variable, allowing for action like&lt;/P&gt;
&lt;P&gt;string_base=catt (string_base, string_add);&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 14:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/length-of-character-variable-in-SAS-IML/m-p/789721#M5747</guid>
      <dc:creator>FelixSta20</dc:creator>
      <dc:date>2022-01-12T14:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: length of  character variable in SAS/IML;</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/length-of-character-variable-in-SAS-IML/m-p/789741#M5748</link>
      <description>&lt;P&gt;The issue you are encountering is because certain Base SAS concatenation functions (CAT, CATS, CATT, CATX, etc) set the length of an uninitialized variable to 200. If the return value from the function exceeds that length, you will get a warning, such as in the following DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* some concatenation functions implicitly set the 
   length that for an unitialized LHS variable to 200 */
data _null_;
s = catt("A", "B");     /* implicitly sets LENGTH s $200 */

/* make a long string */
x1 = "1234567890123456789012345678901234567890";  /* 40 char */
x2 = x1; x3 = x1; x4 = x1; x5 = x1; x6 = x1;
s2 = catt(x1, x2, x3, x4, x5, x6);    /* WARNING: RHS does not fit into length=200 */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log displays&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WARNING: In a call to the CATT function, the buffer allocated
         for the result was not long enough to contain the
         concatenation of all the arguments. The correct result
         would contain 240 characters, but the actual result
         might either be truncated to 200 character(s) or be
         completely blank, depending on the calling
         environment. The following note indicates the
         left-most argument that caused truncation.
&lt;/PRE&gt;
&lt;P&gt;If you call one of the "CAT" functions from IML, you will get similar behavior and the WARNING is coming from the Base function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the DATA step, you work around this issue by using the LENGTH statement to allocate the left-hand side variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length s2 $240;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because IML uses dynamic allocation for each statement, there is no LENGTH statement in the IML language. Instead, I think you can work around this issue in IML by using the built-in '+' operator, which is the IML version of the concatenation functions. You can combine the '+' operator with the STRIP or TRIM functions if you need to remove blanks.&amp;nbsp; The following IML program reads in long strings and uses the '+' operator to concatenate them. You can see that the resulting strings are longer than 200 characters:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
/* make long strings */
length s1 s2 $240 x1-x6 $50;
x1 = "1234567890123456789012345678901234567890";  /* 40 char */
x2 = x1; x3 = x1; x4 = x1; x5 = x1; x6 = x1; 
s1 = catt(x1, x2, x3, x4, x5, x6);
s2 = s1;
run;


proc iml;
use Have;
read all var {s1 s2 x1 x2 x3 x4 x5 x6};
close;

s = trim(x1) + trim(x2) + trim(x3) + 
    trim(x4) + trim(x5) + trim(x6);
nlen = nleng(s);
len = length(s);
print nlen len;

s = trim(s1) + trim(s2);
nlen = nleng(s);
len = length(s);
print nlen len;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 15:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/length-of-character-variable-in-SAS-IML/m-p/789741#M5748</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-01-12T15:02:34Z</dc:date>
    </item>
  </channel>
</rss>

