<?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: Long to Wide with Concatenate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide-with-Concatenate/m-p/543028#M150103</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38234"&gt;@angeliquec&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;No&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Fine. Try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=work.have nway;
   class name color;
   output out=work.counted(drop=_type_ rename=(_freq_ = count));
run;

proc sort data=work.counted;
   by name count;
run;

data work.want;
   set work.counted;
   by name count;

   length colorList $ 50;
   retain colorList;

   if first.count then do;
      colorList = ' ';
   end;

   colorList = catx(',', colorList, color);

   if last.count then do;
      output;
   end;

   drop color;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 14 Mar 2019 06:27:08 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2019-03-14T06:27:08Z</dc:date>
    <item>
      <title>Long to Wide with Concatenate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide-with-Concatenate/m-p/543013#M150092</link>
      <description>&lt;P&gt;*Hi, I have this dataset that I want to group by name and color, and count by this combination.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input name $ color $;&lt;BR /&gt;cards;&lt;BR /&gt;ann green&lt;BR /&gt;ann blue&lt;BR /&gt;ann yellow&lt;BR /&gt;ann blue&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*In the event that there are ties in count by 2 (or more) groups, I'd like to place the list of these groups in the same column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;input name $ color :$20. count;&lt;BR /&gt;cards;&lt;BR /&gt;ann green,yellow 1&lt;BR /&gt;ann blue 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 05:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide-with-Concatenate/m-p/543013#M150092</guid>
      <dc:creator>angeliquec</dc:creator>
      <dc:date>2019-03-14T05:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Long to Wide with Concatenate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide-with-Concatenate/m-p/543017#M150094</link>
      <description>&lt;P&gt;Is it necessary to preserve the order of colors in the result dataset?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 05:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide-with-Concatenate/m-p/543017#M150094</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-14T05:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Long to Wide with Concatenate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide-with-Concatenate/m-p/543025#M150100</link>
      <description>&lt;P&gt;No&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 06:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide-with-Concatenate/m-p/543025#M150100</guid>
      <dc:creator>angeliquec</dc:creator>
      <dc:date>2019-03-14T06:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Long to Wide with Concatenate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide-with-Concatenate/m-p/543027#M150102</link>
      <description>&lt;P&gt;You may have to fiddle with this slightly but it should get you going.&amp;nbsp; You'll also need to test with more realistic data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input name $ color $;
cards;
ann green
ann blue
ann yellow
ann blue
;
run;

proc sql;
   create table counts as
   select 
      *,
      count(0) as count
   from
      have
   group by
      name, color
   order by
      name, count, color
   ;
quit;

data want (drop=color rename=(buffer=color));
   format name buffer color count;  * sets PDV order ;
   length buffer $100;
   do until (last.count);
      set counts;
      by name count color;
      buffer=catx(',',buffer,color);
   end;
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, 14 Mar 2019 06:59:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide-with-Concatenate/m-p/543027#M150102</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2019-03-14T06:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: Long to Wide with Concatenate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide-with-Concatenate/m-p/543028#M150103</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/38234"&gt;@angeliquec&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;No&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Fine. Try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=work.have nway;
   class name color;
   output out=work.counted(drop=_type_ rename=(_freq_ = count));
run;

proc sort data=work.counted;
   by name count;
run;

data work.want;
   set work.counted;
   by name count;

   length colorList $ 50;
   retain colorList;

   if first.count then do;
      colorList = ' ';
   end;

   colorList = catx(',', colorList, color);

   if last.count then do;
      output;
   end;

   drop color;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Mar 2019 06:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Long-to-Wide-with-Concatenate/m-p/543028#M150103</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-14T06:27:08Z</dc:date>
    </item>
  </channel>
</rss>

