<?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: cats function problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/cats-function-problem/m-p/642847#M191825</link>
    <description>&lt;P&gt;Please try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
Header='016420502CCBC07BCC012001071220000BC07BCC025601071540397BC07BCC028201071220000ES02**';
String='BC07BCC002101010BC07BCC0206010423.4BC07BCC00440102-3';
string2=cats(substr(Header,1,prxmatch('m/ES02/oi',header)-1),String,substr(Header,prxmatch('m/ES02/oi',header),6));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 25 Apr 2020 09:27:29 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2020-04-25T09:27:29Z</dc:date>
    <item>
      <title>cats function problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cats-function-problem/m-p/642843#M191823</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;I get this message when trying to concatenate.&lt;/P&gt;
&lt;P&gt;WARNING:In a call to the CATS function, the buffer allocated for the result was not long enough to contain the concatenation of&amp;nbsp;all the arguments. The correct result would contain 5420 characters, but the actual result might either be truncated to&amp;nbsp;200 character(s) or be completely blank, depending on the calling environment. The following note indicates the left-most&amp;nbsp;argument that caused truncation.&lt;/P&gt;
&lt;P&gt;NOTE: Argument 1 to function CATS('TUEF11846042'[12 of 32000 characters shown],'BC07BCC00210'[12 of 200 characters shown],'ES02**&amp;nbsp;&amp;nbsp;&amp;nbsp;'[12 of 32000 characters shown]) at line 1722 column 14 is invalid.&lt;/P&gt;
&lt;P&gt;I have 3 character variables. Acct, Header, String; I need to add String inside Header after a certain criteria is met.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Note: header is very long. A shortened version of it looks like this:&lt;/P&gt;
&lt;P&gt;Header=016420502CCBC07BCC012001071220000BC07BCC025601071540397BC07BCC028201071220000ES02**&lt;/P&gt;
&lt;P&gt;String=BC07BCC002101010BC07BCC0206010423.4BC07BCC00440102-3&lt;/P&gt;
&lt;P&gt;I need to add String in Header after the last BC07(and its value) .&lt;/P&gt;
&lt;P&gt;Header_new should look like: 016420502CCBC07BCC012001071220000BC07BCC025601071540397BC07BCC028201071220000BC07BCC002101010BC07BCC0206010423.4BC07BCC00440102-3ES02**&lt;/P&gt;
&lt;P&gt;This is my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data want;set have;
  b= find(header,'BC07',-length(header));/*position of last 'BC07'*/
  length_of_value=input(substrn(header,find(header,'BC07',-length(header)) + 13),2.);
  frst_string=substrn(header,1, (find(header,'BC07',-length(header))) + 14 + (input(substrn(header,find(header,'BC07',-length(header)) + 13),2.)));
  last_string=substrn(header,b + 15 + length_of_value,length(header) - b + 15 + length_of_value);
  header_new=cats(frst_string,string,last_string); 
 run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can anyone help me with this? I'm guessing the problem is with the length of the characters but I have no idea how to fix it.&lt;/P&gt;
&lt;P&gt;Thanks in Advance.&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;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Apr 2020 08:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cats-function-problem/m-p/642843#M191823</guid>
      <dc:creator>JT99</dc:creator>
      <dc:date>2020-04-25T08:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: cats function problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cats-function-problem/m-p/642847#M191825</link>
      <description>&lt;P&gt;Please try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
Header='016420502CCBC07BCC012001071220000BC07BCC025601071540397BC07BCC028201071220000ES02**';
String='BC07BCC002101010BC07BCC0206010423.4BC07BCC00440102-3';
string2=cats(substr(Header,1,prxmatch('m/ES02/oi',header)-1),String,substr(Header,prxmatch('m/ES02/oi',header),6));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Apr 2020 09:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cats-function-problem/m-p/642847#M191825</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-25T09:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: cats function problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cats-function-problem/m-p/642854#M191829</link>
      <description>&lt;P&gt;See Maxim 47: Set a Length.&lt;/P&gt;
&lt;P&gt;Add&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length header_new $5420;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;before the function call.&lt;/P&gt;
&lt;P&gt;The SAS datastep compiler defines most new character variables found to the left of a character function with a default length of 200 if no other is specified.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Apr 2020 10:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cats-function-problem/m-p/642854#M191829</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-25T10:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: cats function problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cats-function-problem/m-p/642893#M191845</link>
      <description>&lt;P&gt;Your code has 5 assignment statements.&amp;nbsp; Do any of the variables being given values already exist in HAVE?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not then the SAS data step compiler will make a guess at how to define them.&lt;/P&gt;
&lt;P&gt;The first two are assigning numeric values, so they will be created as numbers.&lt;/P&gt;
&lt;P&gt;The next three are being assigned character values, so they will be created as character, but the compiler needs to make a guess at what length you wanted for them.&amp;nbsp; For the first two since it is the result of SUBSTRN() on HEADER they will be set to the same length as HEADER.&lt;/P&gt;
&lt;P&gt;But the last one is the result of the CATS() function call.&amp;nbsp; So the compiler has no way to know what possible length to use, so it uses $200.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ALWAYS define your variables before using them.&amp;nbsp; You can use the LENGTH statement or the LENGTH= option on the ATTRIB statement.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Apr 2020 16:20:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cats-function-problem/m-p/642893#M191845</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-25T16:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: cats function problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cats-function-problem/m-p/642969#M191861</link>
      <description>Thank you! My code is now working!</description>
      <pubDate>Sat, 25 Apr 2020 23:51:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cats-function-problem/m-p/642969#M191861</guid>
      <dc:creator>JT99</dc:creator>
      <dc:date>2020-04-25T23:51:48Z</dc:date>
    </item>
  </channel>
</rss>

