<?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: Adding another row based on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-another-row-based-on-condition/m-p/413927#M101375</link>
    <description>&lt;P&gt;This is a basic array and loop question, keep adding strings from the array until length is exceeded:&amp;nbsp; Post test data in the form of a datastep to get working code, this is just and example (as I am not here to type test data in for you!!).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;data want (keep=name account);
  length account $36;
  set have;
  array account{6};
  do i=1 to 6;
    if lengthn(catx(" ",account,account{i})) &amp;gt; 36 then do;
      output;
      account=account{i};
    end;
    else account=catx(" ",account,account{i});
  end;
run;
  
  &lt;/PRE&gt;</description>
    <pubDate>Thu, 16 Nov 2017 08:58:34 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-11-16T08:58:34Z</dc:date>
    <item>
      <title>Adding another row based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-another-row-based-on-condition/m-p/413920#M101369</link>
      <description>&lt;P&gt;I have the following dataset:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Name&lt;/TD&gt;&lt;TD&gt;Account1&lt;/TD&gt;&lt;TD&gt;Account2&lt;/TD&gt;&lt;TD&gt;Account3&lt;/TD&gt;&lt;TD&gt;Account5&lt;/TD&gt;&lt;TD&gt;Account6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;234567899&lt;/TD&gt;&lt;TD&gt;4735362537256894&lt;/TD&gt;&lt;TD&gt;534254635636456&lt;/TD&gt;&lt;TD&gt;324526453647&lt;/TD&gt;&lt;TD&gt;325423642364&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XYZ&lt;/TD&gt;&lt;TD&gt;231254312563&lt;/TD&gt;&lt;TD&gt;24653242364351&lt;/TD&gt;&lt;TD&gt;24254523453764&lt;/TD&gt;&lt;TD&gt;245534235452&lt;/TD&gt;&lt;TD&gt;26354245214&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to concatenate all the account columns into one&amp;nbsp;column with space as delimiter. But the concatenated account field can't&amp;nbsp;have more than 36 characters. When I am adding the accounts to the concatenated account field, if it's&amp;nbsp;length exceeds 36 characters then I need to insert a new row with the same name and concatenate the rest of the accounts in the second row and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Output for the above dataset should look like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Name&lt;/TD&gt;&lt;TD&gt;Account&lt;/TD&gt;&lt;TD&gt;Length_Of_Account&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;234567899 4735362537256894&lt;/TD&gt;&lt;TD&gt;26&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;534254635636456 324526453647&lt;/TD&gt;&lt;TD&gt;28&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;325423642364&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XYZ&lt;/TD&gt;&lt;TD&gt;231254312563 24653242364351&lt;/TD&gt;&lt;TD&gt;27&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XYZ&lt;/TD&gt;&lt;TD&gt;24254523453764 245534235452&lt;/TD&gt;&lt;TD&gt;27&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XYZ&lt;/TD&gt;&lt;TD&gt;26354245214&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The length column is just for reference - If the account3 was added to the concatenated variable for name ABC, then the length would exceed 36 - so a new row has to be created and the next accounts should be added in that row.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm very new to SAS - I am able to concatenate using catx but I am not sure how to achieve the rest of it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 08:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-another-row-based-on-condition/m-p/413920#M101369</guid>
      <dc:creator>cybharg</dc:creator>
      <dc:date>2017-11-16T08:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: Adding another row based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-another-row-based-on-condition/m-p/413921#M101370</link>
      <description>&lt;P&gt;So the concatenated field is allowed to contain spaces? It would help a lot if you outline how your desired output data set looks just like you posted what data you have &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2017 08:08:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-another-row-based-on-condition/m-p/413921#M101370</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-11-16T08:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: Adding another row based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-another-row-based-on-condition/m-p/413925#M101374</link>
      <description>Thanks... I've added the Output</description>
      <pubDate>Thu, 16 Nov 2017 08:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-another-row-based-on-condition/m-p/413925#M101374</guid>
      <dc:creator>cybharg</dc:creator>
      <dc:date>2017-11-16T08:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Adding another row based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-another-row-based-on-condition/m-p/413927#M101375</link>
      <description>&lt;P&gt;This is a basic array and loop question, keep adding strings from the array until length is exceeded:&amp;nbsp; Post test data in the form of a datastep to get working code, this is just and example (as I am not here to type test data in for you!!).&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;data want (keep=name account);
  length account $36;
  set have;
  array account{6};
  do i=1 to 6;
    if lengthn(catx(" ",account,account{i})) &amp;gt; 36 then do;
      output;
      account=account{i};
    end;
    else account=catx(" ",account,account{i});
  end;
run;
  
  &lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Nov 2017 08:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-another-row-based-on-condition/m-p/413927#M101375</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-16T08:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Adding another row based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-another-row-based-on-condition/m-p/413954#M101382</link>
      <description>&lt;P&gt;Not pretty but does the job&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Name$ Account1:$36. Account2:$36. Account3:$36. Account5:$36. Account6:$36.;
datalines; 
ABC 234567899 4735362537256894 534254635636456 324526453647 325423642364 
XYZ 231254312563 24653242364351 24254523453764 245534235452 26354245214 
;

data want(keep= Name Account);
	set have;
	length Account $100;

	array acc{*} Account1 Account2 Account3 Account5 Account6;
	l=0;

	do i=1 to dim(acc);
		l=l+length(acc[i]);
		if l&amp;lt;36 then do;
			Account=catx(' ', Account, acc[i]);
		end;
		else do;
			i=i-1;
			output;
			l=0;
			Account='';
		end;

	if i=dim(acc) then output;
	end;

	retain l;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Nov 2017 10:47:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-another-row-based-on-condition/m-p/413954#M101382</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-11-16T10:47:16Z</dc:date>
    </item>
  </channel>
</rss>

