<?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: Concatenating strings in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361699#M85354</link>
    <description>&lt;P&gt;The code I posted put the result in the variable s. Below puts the result back in the variable review.&lt;/P&gt;&lt;P&gt;I don't know how to copy SAS output into this post, but you can run the code below freestanding. I think the output looks like what was in the original post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data raw;
input name$ review$;
datalines;
abc ghffh
abc fhgfh
efg gggh
efg fgfg
efg gff
efg ghgh
cgc thf
cgc tyg
;
run;

proc sort data = raw;
	by name;
run;
data want;
	length review $ 100;
	set raw (rename = (review = r));
	by name;
	retain review i;
	if first.name then do;
		i = 1;
		review = catx(' ',name,cats(i,'.',r));
	end;
	else do;
		i = i + 1;
		review = catx('; ',review,cats(i,'.',r));
	end;
	if last.name;
	keep name review;

run;
proc print data = want;
var name review;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 25 May 2017 17:20:29 GMT</pubDate>
    <dc:creator>sschleede</dc:creator>
    <dc:date>2017-05-25T17:20:29Z</dc:date>
    <item>
      <title>Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361634#M85323</link>
      <description>&lt;P&gt;Hi SAS Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am tryng to add multiple strings into one cell for distinct name. Attched are two files 1.raw data file 2.needed output file.&lt;/P&gt;
&lt;P&gt;Is there is a way &amp;nbsp;to get the results in (2). needed output file using sas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;
&lt;P&gt;Sanjay.&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 14:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361634#M85323</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-05-25T14:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361636#M85324</link>
      <description>&lt;P&gt;I can't see the difference in CSV - may be my device.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please consider posting the requirements directly into the forum.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 14:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361636#M85324</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-25T14:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361647#M85328</link>
      <description>&lt;P&gt;This is the raw file look like.&lt;/P&gt;&lt;P&gt;data raw;&lt;BR /&gt;input name$ review$;&lt;BR /&gt;datalines;&lt;BR /&gt;abc ghffh&lt;BR /&gt;abc fhgfh&lt;BR /&gt;efg gggh&lt;BR /&gt;efg fgfg&lt;BR /&gt;efg gff&lt;BR /&gt;efg ghgh&lt;BR /&gt;cgc thf&lt;BR /&gt;cgc tyg&lt;BR /&gt;;&lt;BR /&gt;run;&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;This is the needed output.&lt;/P&gt;&lt;P&gt;name &amp;nbsp;review&lt;/P&gt;&lt;P&gt;abc&amp;nbsp;1.ghffh; 2.fhgfh&lt;/P&gt;&lt;P&gt;efg &amp;nbsp;1.gggh; 2.fgfg; 3.gff; 4.ghgh&lt;/P&gt;&lt;P&gt;cgc &amp;nbsp;1.thf; 2.tyg&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 15:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361647#M85328</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-05-25T15:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361652#M85330</link>
      <description>&lt;P&gt;This is what I came up with. Comment out the keep statement and the if last.name statement if you want to see how it is building up s for each record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = raw;
	by name;
run;
data want;
	length s $ 100;
	set raw;
	by name;
	retain s i;
	if first.name then do;
		i = 1;
		s = catx(' ',name,cats(i,'.',review));
	end;
	else do;
		i = i + 1;
		s = catx('; ',s,cats(i,'.',review));
	end;
	if last.name;
	keep s;

run;
proc print data = want;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 15:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361652#M85330</guid>
      <dc:creator>sschleede</dc:creator>
      <dc:date>2017-05-25T15:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361656#M85334</link>
      <description>&lt;P&gt;Another method is to transpose to a wide file via PROC TRANSPOSE and then use CATX on the new variable with an array.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 15:30:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361656#M85334</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-25T15:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361671#M85342</link>
      <description>&lt;P&gt;Hi sschleede,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Its working fine,but i want name as separate variable and all the reviews concatenated into one cell.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 16:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361671#M85342</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-05-25T16:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361674#M85344</link>
      <description>&lt;P&gt;I'm confused, isn't that exactly what the code does? Please explain in detail.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91059"&gt;@sanjay1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi sschleede,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its working fine,but i want name as separate variable and all the reviews concatenated into one cell.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 16:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361674#M85344</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-25T16:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361680#M85347</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91059"&gt;@sanjay1&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi sschleede,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its working fine,but i want name as separate variable and all the reviews concatenated into one cell.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show the actual results your a getting if that is not the case. Perhaps your data isn't actually as you posted for the example?&lt;/P&gt;</description>
      <pubDate>Thu, 25 May 2017 16:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361680#M85347</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-25T16:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361699#M85354</link>
      <description>&lt;P&gt;The code I posted put the result in the variable s. Below puts the result back in the variable review.&lt;/P&gt;&lt;P&gt;I don't know how to copy SAS output into this post, but you can run the code below freestanding. I think the output looks like what was in the original post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data raw;
input name$ review$;
datalines;
abc ghffh
abc fhgfh
efg gggh
efg fgfg
efg gff
efg ghgh
cgc thf
cgc tyg
;
run;

proc sort data = raw;
	by name;
run;
data want;
	length review $ 100;
	set raw (rename = (review = r));
	by name;
	retain review i;
	if first.name then do;
		i = 1;
		review = catx(' ',name,cats(i,'.',r));
	end;
	else do;
		i = i + 1;
		review = catx('; ',review,cats(i,'.',r));
	end;
	if last.name;
	keep name review;

run;
proc print data = want;
var name review;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 May 2017 17:20:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361699#M85354</guid>
      <dc:creator>sschleede</dc:creator>
      <dc:date>2017-05-25T17:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361704#M85356</link>
      <description>&lt;P&gt;OK. I reread the request. I was reading the output as 'abc 1.ghffh; 2. fhgfh' instead of 'abc' and '1.ghffh; 2. fhgfh'.&lt;/P&gt;&lt;P&gt;Small change to the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data raw;
input name$ review$;
datalines;
abc ghffh
abc fhgfh
efg gggh
efg fgfg
efg gff
efg ghgh
cgc thf
cgc tyg
;
run;

proc sort data = raw;
	by name;
run;
data want;
	length review $ 100;
	set raw (rename = (review = r));
	by name;
	retain review i;
	if first.name then do;
		i = 1;
		review = cats(i,'.',r);
	end;
	else do;
		i = i + 1;
		review = catx('; ',review,cats(i,'.',r));
	end;
	if last.name;
	keep name review;

run;
proc print data = want;
var name review;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 May 2017 17:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361704#M85356</guid>
      <dc:creator>sschleede</dc:creator>
      <dc:date>2017-05-25T17:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361709#M85357</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data raw;
    input name$ review$;
    datalines;
abc ghffh
abc fhgfh
efg gggh
efg fgfg
efg gff
efg ghgh
cgc thf
cgc tyg
;
run;

proc sort data=raw;
    by name;

data raw;
    set raw;
    by name;

    if first.name then
        count=1;
    else
        count+1;
    review=catt(count, ".", review);
run;

proc transpose data=raw out=wide prefix=rv_;
    by name;
    var review;
    id count;
run;

data want;
    set wide;
    review=catx("; ", of rv_:);
    drop _name_ rv_:;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 May 2017 17:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361709#M85357</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-25T17:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361922#M85433</link>
      <description>&lt;P&gt;Thank you It worked for me&lt;/P&gt;</description>
      <pubDate>Fri, 26 May 2017 11:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-strings/m-p/361922#M85433</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2017-05-26T11:09:16Z</dc:date>
    </item>
  </channel>
</rss>

