<?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: combine this into single variable in SAS Software for Learning Community</title>
    <link>https://communities.sas.com/t5/SAS-Software-for-Learning/combine-this-into-single-variable/m-p/828124#M581</link>
    <description>&lt;P&gt;Try this. I added an extra ID to clarify that it handles multiple by groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID NAME $;
datalines;
1 Animesh 
1 Mardi   
1 ABC     
2 Animesh 
2 Mardi   
2 ABC     
;

data want(drop = name);
   do until (last.ID);
      set have;
      by ID;
      length n $200;
      n = catx(' ', n, name);
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 10 Aug 2022 17:15:54 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-08-10T17:15:54Z</dc:date>
    <item>
      <title>combine this into single variable</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/combine-this-into-single-variable/m-p/828106#M579</link>
      <description>&lt;P&gt;ID&amp;nbsp; &amp;nbsp; NAME&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; Animesh&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; Mardi&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; ABC&lt;/P&gt;&lt;P&gt;How to combine this into single variable&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Output should be :-&amp;nbsp; 1 Animesh Mardi abc&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 15:03:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/combine-this-into-single-variable/m-p/828106#M579</guid>
      <dc:creator>animesh123</dc:creator>
      <dc:date>2022-08-10T15:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: combine this into single variable</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/combine-this-into-single-variable/m-p/828107#M580</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
    by ID;
run;

**********************************************************************;
*Use RETAIN and BY group processing to combine the information;
**********************************************************************;
data want_option1;
    set have;
    by ID;
    length combined $100.;
    retain combined;

    if first.ID then
        combined=name;
    else
        combined=catx(', ', combined, name);

    if last.ID then
        output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=wide prefix=name_;
    by ID;
    var name;
run;

data want_option2;
    set wide;
    length combined $100.;
    combined=catx(', ', of name_:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/430763"&gt;@animesh123&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; NAME&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; Animesh&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; Mardi&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; ABC&lt;/P&gt;
&lt;P&gt;How to combine this into single variable&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Output should be :-&amp;nbsp; 1 Animesh Mardi abc&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 15:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/combine-this-into-single-variable/m-p/828107#M580</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-08-10T15:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: combine this into single variable</title>
      <link>https://communities.sas.com/t5/SAS-Software-for-Learning/combine-this-into-single-variable/m-p/828124#M581</link>
      <description>&lt;P&gt;Try this. I added an extra ID to clarify that it handles multiple by groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID NAME $;
datalines;
1 Animesh 
1 Mardi   
1 ABC     
2 Animesh 
2 Mardi   
2 ABC     
;

data want(drop = name);
   do until (last.ID);
      set have;
      by ID;
      length n $200;
      n = catx(' ', n, name);
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Aug 2022 17:15:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Software-for-Learning/combine-this-into-single-variable/m-p/828124#M581</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-10T17:15:54Z</dc:date>
    </item>
  </channel>
</rss>

