<?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: group by with concatenate over rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/group-by-with-concatenate-over-rows/m-p/826800#M326583</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Loans;
input ID  Type amount month;
cards;
11111 712 1000 2201
11111 987 2000 2201
11111 712 3000 2201
11111 712 5000 2202
22222 712 4300 2201
22222 987 1500 2201
;
Run;

proc summary data = Loans nway;
   class ID month type;
   var amount;
   output out = temp(drop = _:) sum=;
run;

data want(drop = type amount);
   set temp;
   by ID month;

   length con_type_amount $200;
   con_type_amount = catx(',', con_type_amount, cats('(', type, '-', amount, ')')); 

   if last.month then do;
      output;
      call missing(con_type_amount);
   end;

   retain con_type_amount;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID     month  con_type_amount      
11111  2201   (712-4000),(987-2000)
11111  2202   (712-5000)           
22222  2201   (712-4300),(987-1500) &lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Aug 2022 08:44:00 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-08-03T08:44:00Z</dc:date>
    <item>
      <title>group by with concatenate over rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-by-with-concatenate-over-rows/m-p/826797#M326581</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with loans information.&lt;/P&gt;
&lt;P&gt;Each customer can appear in multiple rows (If he took multiple loans)..&lt;/P&gt;
&lt;P&gt;I want to create a summary table that each customerID will appear in 1 row per month (YYMM).&lt;/P&gt;
&lt;P&gt;In the wanted data set will have 3 columns:&lt;/P&gt;
&lt;P&gt;ID&lt;/P&gt;
&lt;P&gt;month&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Concatenate_Type_Amount&lt;/P&gt;
&lt;P&gt;What is the way to create this data set please?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1659508920806.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74041iBA6B60F34C848594/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1659508920806.png" alt="Ronein_0-1659508920806.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data Loans;
input ID  Type amount month;
cards;
11111 712 1000 2201
11111 987 2000 2201
11111 712 3000 2201
11111 712 5000 2202
22222 712 4300 2201
22222 987 1500 2201
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The wanted data set will have 3 rows:&lt;/P&gt;
&lt;P&gt;/*Wanted table*/&lt;BR /&gt;/*11111 2201 (712-4000),(987-2000)*/&lt;BR /&gt;/*11111 2202 (712-5000)*/&lt;BR /&gt;/*22222 2201 (712-4300),(987-1500)*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 06:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-by-with-concatenate-over-rows/m-p/826797#M326581</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-08-03T06:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: group by with concatenate over rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-by-with-concatenate-over-rows/m-p/826800#M326583</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Loans;
input ID  Type amount month;
cards;
11111 712 1000 2201
11111 987 2000 2201
11111 712 3000 2201
11111 712 5000 2202
22222 712 4300 2201
22222 987 1500 2201
;
Run;

proc summary data = Loans nway;
   class ID month type;
   var amount;
   output out = temp(drop = _:) sum=;
run;

data want(drop = type amount);
   set temp;
   by ID month;

   length con_type_amount $200;
   con_type_amount = catx(',', con_type_amount, cats('(', type, '-', amount, ')')); 

   if last.month then do;
      output;
      call missing(con_type_amount);
   end;

   retain con_type_amount;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID     month  con_type_amount      
11111  2201   (712-4000),(987-2000)
11111  2202   (712-5000)           
22222  2201   (712-4300),(987-1500) &lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Aug 2022 08:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-by-with-concatenate-over-rows/m-p/826800#M326583</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-03T08:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: group by with concatenate over rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-by-with-concatenate-over-rows/m-p/827238#M326760</link>
      <description>One question please:&lt;BR /&gt;What is the reason to use " call missing(con_Degem_amount);" ?&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Aug 2022 21:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-by-with-concatenate-over-rows/m-p/827238#M326760</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-08-04T21:29:19Z</dc:date>
    </item>
  </channel>
</rss>

