<?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 Concatenate in do loop with keep blanks doesn't work in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-do-loop-with-keep-blanks-doesn-t-work/m-p/371557#M88772</link>
    <description>&lt;P&gt;I try to concatenate a text-string with a do loop. the functions catt, cats and catx works, but cat doesn't. but i need the blanks in the ouptut string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data want;

	length string_in string_out_cat string_out_cats string_out_catt string_out_catx $200 c $1;

	string_in = "this is a textstring";
	do i = 1 to lengthc(string_in);
		c = substr(string_in,i,1);
		string_out_cat = cat(string_out_cat,c);
		string_out_cats = cats(string_out_cats,c);
		string_out_catt = catt(string_out_catt,c);
		string_out_catx = catx("*",string_out_catx,c);
	end;

	

run;


&lt;/PRE&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/9961i39D2AC42D68870AA/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="concat.PNG" title="concat.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any ideas?&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jun 2017 07:44:44 GMT</pubDate>
    <dc:creator>optimus</dc:creator>
    <dc:date>2017-06-29T07:44:44Z</dc:date>
    <item>
      <title>Concatenate in do loop with keep blanks doesn't work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-do-loop-with-keep-blanks-doesn-t-work/m-p/371557#M88772</link>
      <description>&lt;P&gt;I try to concatenate a text-string with a do loop. the functions catt, cats and catx works, but cat doesn't. but i need the blanks in the ouptut string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data want;

	length string_in string_out_cat string_out_cats string_out_catt string_out_catx $200 c $1;

	string_in = "this is a textstring";
	do i = 1 to lengthc(string_in);
		c = substr(string_in,i,1);
		string_out_cat = cat(string_out_cat,c);
		string_out_cats = cats(string_out_cats,c);
		string_out_catt = catt(string_out_catt,c);
		string_out_catx = catx("*",string_out_catx,c);
	end;

	

run;


&lt;/PRE&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/9961i39D2AC42D68870AA/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="concat.PNG" title="concat.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any ideas?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 07:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-do-loop-with-keep-blanks-doesn-t-work/m-p/371557#M88772</guid>
      <dc:creator>optimus</dc:creator>
      <dc:date>2017-06-29T07:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in do loop with keep blanks doesn't work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-do-loop-with-keep-blanks-doesn-t-work/m-p/371580#M88778</link>
      <description>&lt;P&gt;This is due to the way strings are handled. &amp;nbsp;When you set a new variable of a given length, say 5 in this case then the variable is:&lt;/P&gt;
&lt;P&gt;[][][][][]&lt;/P&gt;
&lt;P&gt;Now if you choose the procedure that keeps blanks and concatenates variables and add ABCDE:&lt;/P&gt;
&lt;P&gt;[][][][][][a][b][c][d][e]&lt;/P&gt;
&lt;P&gt;Then put that back into the chracter that has length 5 it chops the end off, hence the variable can only contain 5 spaces.&lt;/P&gt;
&lt;P&gt;Thus the question back to you is what do you expect the output to look like? &amp;nbsp;is it a space between words, or letters? &amp;nbsp;If its words then you would be better off doing:&lt;/P&gt;
&lt;PRE&gt;data want;
  ...
  do i=1 to countw(string," ");
    word=scan(string,i," ");
  end;
run;&lt;/PRE&gt;
&lt;P&gt;If its each letter, then catx() would be the function. &amp;nbsp;But without further info I can't say.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jun 2017 09:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-do-loop-with-keep-blanks-doesn-t-work/m-p/371580#M88778</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-29T09:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in do loop with keep blanks doesn't work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-do-loop-with-keep-blanks-doesn-t-work/m-p/371592#M88781</link>
      <description>&lt;P&gt;Thanks for your answer. This was the hint I needed.&amp;nbsp;Now it make sence.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to keep the space between the word, but I have to loop / process each letter. So the final solution is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data want (drop=c i ablank);

	length string_in string_out $50 c $1;

	string_in = "this is a textstring";
	ablank=0;

	do i = 1 to lengthc(string_in);
		c = substr(string_in,i,1);
		
		if ablank=1 then string_out = cat(strip(string_out)," ",c);
		else string_out = cat(strip(string_out),c);
		
		if c=" " then ablank=1;
		else ablank=0;
			
	end;

run;

&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jun 2017 10:02:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-do-loop-with-keep-blanks-doesn-t-work/m-p/371592#M88781</guid>
      <dc:creator>optimus</dc:creator>
      <dc:date>2017-06-29T10:02:00Z</dc:date>
    </item>
  </channel>
</rss>

