<?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 If variable length greater 32767 then How to keep the remaining character in different variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651457#M195465</link>
    <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to concatenate all the rows from each group. I have written a code from which I am getting my desire result in last line(using last.) but problem is , it is only keeping up to 32767 characters. I am looking for a solution, if the character limit reaches 32767 then in the next variable (column) the remaining character should add. I am using the below code but it is not spiting into different variable if limit reaches. I have attached the result. Any help will be appreciated. Many thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data part4 (keep=DOC_NUMBER original_variable count);&lt;BR /&gt;set part3;&lt;BR /&gt;BY DOC_NUMBER;&lt;BR /&gt;if FIRST.DOC_NUMBER then&lt;BR /&gt;Count = 0;&lt;BR /&gt;Count + 1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data part5;&lt;BR /&gt;length concatenated_field $ 32767;&lt;BR /&gt;retain concatenated_field;&lt;BR /&gt;set part4;&lt;BR /&gt;by DOC_NUMBER;&lt;BR /&gt;if first.DOC_NUMBER then&lt;BR /&gt;do;&lt;BR /&gt;concatenated_field = original_variable;&lt;BR /&gt;end;&lt;BR /&gt;else&lt;BR /&gt;do;&lt;BR /&gt;concatenated_field = catx(', ', concatenated_field, original_variable);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 28 May 2020 16:18:48 GMT</pubDate>
    <dc:creator>benhaz</dc:creator>
    <dc:date>2020-05-28T16:18:48Z</dc:date>
    <item>
      <title>If variable length greater 32767 then How to keep the remaining character in different variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651457#M195465</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to concatenate all the rows from each group. I have written a code from which I am getting my desire result in last line(using last.) but problem is , it is only keeping up to 32767 characters. I am looking for a solution, if the character limit reaches 32767 then in the next variable (column) the remaining character should add. I am using the below code but it is not spiting into different variable if limit reaches. I have attached the result. Any help will be appreciated. Many thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data part4 (keep=DOC_NUMBER original_variable count);&lt;BR /&gt;set part3;&lt;BR /&gt;BY DOC_NUMBER;&lt;BR /&gt;if FIRST.DOC_NUMBER then&lt;BR /&gt;Count = 0;&lt;BR /&gt;Count + 1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data part5;&lt;BR /&gt;length concatenated_field $ 32767;&lt;BR /&gt;retain concatenated_field;&lt;BR /&gt;set part4;&lt;BR /&gt;by DOC_NUMBER;&lt;BR /&gt;if first.DOC_NUMBER then&lt;BR /&gt;do;&lt;BR /&gt;concatenated_field = original_variable;&lt;BR /&gt;end;&lt;BR /&gt;else&lt;BR /&gt;do;&lt;BR /&gt;concatenated_field = catx(', ', concatenated_field, original_variable);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 16:18:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651457#M195465</guid>
      <dc:creator>benhaz</dc:creator>
      <dc:date>2020-05-28T16:18:48Z</dc:date>
    </item>
    <item>
      <title>If variable length greater than 32767 then How to keep the remaining character in different variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651464#M195471</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to concatenate all the rows from each group. I have written a code from which I am getting my desire result in last line(using last.) but problem is , it is only keeping up to 32767 characters. I am looking for a solution, if the character limit reaches 32767 then in the next variable (column) the remaining character should add. I am using the below code but it is not spiting into different variable if limit reaches. I have attached the result. Any help will be appreciated. Many thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data part4 (keep=DOC_NUMBER original_variable count);&lt;BR /&gt;set part3;&lt;BR /&gt;BY DOC_NUMBER;&lt;BR /&gt;if FIRST.DOC_NUMBER then&lt;BR /&gt;Count = 0;&lt;BR /&gt;Count + 1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data part5;&lt;BR /&gt;length concatenated_field $ 32767;&lt;BR /&gt;retain concatenated_field;&lt;BR /&gt;set part4;&lt;BR /&gt;by DOC_NUMBER;&lt;BR /&gt;if first.DOC_NUMBER then&lt;BR /&gt;do;&lt;BR /&gt;concatenated_field = original_variable;&lt;BR /&gt;end;&lt;BR /&gt;else&lt;BR /&gt;do;&lt;BR /&gt;concatenated_field = catx(', ', concatenated_field, original_variable);&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 16:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651464#M195471</guid>
      <dc:creator>benhaz</dc:creator>
      <dc:date>2020-05-28T16:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: If variable length greater 32767 then How to keep the remaining character in different variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651466#M195468</link>
      <description>&lt;P&gt;Maybe something like this, completely untested because no actual data was provided (PDF does not count as data, I can't write code to use it).&lt;/P&gt;
&lt;PRE&gt;data part5;
   length concatenated_field concatenated_field2 $ 32767;
   retain concatenated_field concatenated_field2;
   set part4;
   by DOC_NUMBER;
   if first.DOC_NUMBER then  do;
      concatenated_field = original_variable;
      call missing(concatenated_field2);
   end;
   else do;
      if length(concatenated_field) + length(orginal_variable) le 32767 
         and missing(concatenated_field2) then
      concatenated_field = catx(', ', concatenated_field, original_variable);
      else concatenated_field2=  catx(', ', concatenated_field2, original_variable);
   end;
run;&lt;/PRE&gt;
&lt;P&gt;As always, I will ask: Why do you think you need that concatenated value at all? It is very likely to be extremely difficult to do anything with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what is the PDF attachment supposed to tell us? It doesn't show anything approaching the maximum length and the circled "Group 1" and "Group 2" are not discussed at all in your question.&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 19:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651466#M195468</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-28T19:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: If variable length greater 32767 then How to keep the remaining character in different variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651470#M195470</link>
      <description>Why do you want all the text in a single column?    Maybe there is a better solution to your real problem, rather than making a new problem caused by the maximum column length</description>
      <pubDate>Thu, 28 May 2020 16:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651470#M195470</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-05-28T16:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: If variable length greater than 32767 then How to keep the remaining character in different vari</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651480#M195475</link>
      <description>&lt;P&gt;Which version of SAS software do you have?&lt;/P&gt;
&lt;P&gt;If you have SAS 9.4 M5 and above, then you can use a variable of type&amp;nbsp;VARCHAR, which could go beyond the 32767 max length of the Char type.&lt;/P&gt;
&lt;P&gt;&lt;A title="LENGTH Statement" href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=p1hgqgmxm3dpqcn1d4w5za5qbz0d.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt; Check the LENGTH Statement&lt;/A&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 17:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651480#M195475</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2020-05-28T17:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: If variable length greater 32767 then How to keep the remaining character in different variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651483#M195477</link>
      <description>&lt;P&gt;Just use LUA, where there are no limits!&amp;nbsp; (just memory limits).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example of creating a variable which is 100k characters wide:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc lua;
submit;
	local demo
	local example='A'
	local a=1
	repeat
	   example=example..'1234567890'
	   a = a + 1
	until( a &amp;gt;100000 )
	print(string.len(example))
endsubmit;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2020-05-28 at 19.09.32.png" style="width: 894px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/40112i45485E8AC6C195F2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2020-05-28 at 19.09.32.png" alt="Screenshot 2020-05-28 at 19.09.32.png" /&gt;&lt;/span&gt;&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;</description>
      <pubDate>Thu, 28 May 2020 17:10:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651483#M195477</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2020-05-28T17:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: If variable length greater 32767 then How to keep the remaining character in different variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651515#M195484</link>
      <description>&lt;P&gt;Hello Sir,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is working as I wanted. But only one concern if I wanted to split in 3 variable like&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;concatenated_field concatenated_field2 concatenated_field3&lt;/PRE&gt;&lt;P&gt;then where should I edit?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 18:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651515#M195484</guid>
      <dc:creator>benhaz</dc:creator>
      <dc:date>2020-05-28T18:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: If variable length greater 32767 then How to keep the remaining character in different variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651522#M195487</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/256541"&gt;@benhaz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello Sir,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is working as I wanted. But only one concern if I wanted to split in 3 variable like&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;concatenated_field concatenated_field2 concatenated_field3&lt;/PRE&gt;
&lt;P&gt;then where should I edit?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And there we have one reason why this is likely to be a poor idea in general. If you need 3 variables of 32,000+ characters I suspect that you have a need in the future for 4 or 5. And the code gets more complex at each additional variable.&lt;/P&gt;
&lt;P&gt;For example: Do you know why the check for Missing is included here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if length(concatenated_field) + length(orginal_variable) le 32767 and missing(concatenated_field2) then &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reason is because we are checking a total length of the first concatenated plus that of the current. Missing value for the second concatenated variable means that we want to add to the first but once we start adding things to the second we want to keep adding them. Without a lot of knowledge about your actual values this sort of check is needed to prevent having a short value for original_variable that would fit into the 32767 but would be concatenated out of order. So you have to replicate additional checks for each and every other "concatenated variable" you add. With additional If/then/else blocks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You still have not provided any actual use for one, much less 3 variables like this. If you let use know why we may have better suggestions.&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;</description>
      <pubDate>Thu, 28 May 2020 19:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-variable-length-greater-32767-then-How-to-keep-the-remaining/m-p/651522#M195487</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-28T19:30:01Z</dc:date>
    </item>
  </channel>
</rss>

