<?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 rows and creata a new column with values in comma in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Group-rows-and-creata-a-new-column-with-values-in-comma/m-p/443097#M110830</link>
    <description>&lt;PRE&gt;data work.want;
   set work.have;
   by x;  /* assumes data is sorted by this variable
             automatic variables for variables on the 
             by statement are available to indicate the 
             first or last of a group represented by 
             the variable(s)
           */

   length Y_List $ 100; /* specify a length of the target variable
                           long enough to hold the longest expected
                           result
                        */
   retain Y_List;       /* keep the value of the variable between iterations
                           of the data step
                        */

   if first.x then Y_List = ' ';  /* set the target variable to empty at 
                                     the start of each group of X values
                                  */
   Y_List = catx(',', Y_List, Y); /* catx function combines the previous version of the
                                     Y_list variable with the current inserting a comma
                                     note the comma only appears BETWEEN values, not after
                                     the last
                                  */
   if last.x then output;       /* the IF in this form only sends data to the output 
                                   set when the condition is true. The condition
                                   here is that the current X value is the last 
                                   of this group.
                                 */

   drop y;                      /* remove the current value of Y when the data is output*/
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 06 Mar 2018 23:47:08 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-03-06T23:47:08Z</dc:date>
    <item>
      <title>Group rows and creata a new column with values in comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-rows-and-creata-a-new-column-with-values-in-comma/m-p/442765#M110722</link>
      <description>&lt;P&gt;Hello friends,&lt;/P&gt;&lt;P&gt;I want to ask a question please.&lt;/P&gt;&lt;P&gt;I have a data set which includes 4 rows with 2 columns.&lt;/P&gt;&lt;P&gt;X &amp;nbsp; Y&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;I want to create following data set from my data set&lt;/P&gt;&lt;P&gt;X &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;2,3,4&lt;/P&gt;&lt;P&gt;Can anyone help how to do it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Ronein&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 07:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-rows-and-creata-a-new-column-with-values-in-comma/m-p/442765#M110722</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-03-06T07:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Group rows and creata a new column with values in comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-rows-and-creata-a-new-column-with-values-in-comma/m-p/442778#M110724</link>
      <description>&lt;P&gt;This is simple by-group-processing, explained in numerous papers &amp;amp; posts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested, assuming that work.want is sorted by x:&lt;/P&gt;
&lt;PRE&gt;data work.want;
   set work.have;
   by x;

   length Y_List $ 100;
   retain Y_List;

   if first.x then Y_List = ' ';
   Y_List = catx(',', Y_List, Y);
   if last.x then output; 

   drop y;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 07:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-rows-and-creata-a-new-column-with-values-in-comma/m-p/442778#M110724</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-03-06T07:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Group rows and creata a new column with values in comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-rows-and-creata-a-new-column-with-values-in-comma/m-p/442807#M110735</link>
      <description>&lt;P&gt;It is a perfect and very clever solution.&lt;/P&gt;&lt;P&gt;May you please explain the code and steps of process.&lt;/P&gt;&lt;P&gt;I am trying to understand it but couldn't understand.&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 09:21:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-rows-and-creata-a-new-column-with-values-in-comma/m-p/442807#M110735</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-03-06T09:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: Group rows and creata a new column with values in comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-rows-and-creata-a-new-column-with-values-in-comma/m-p/443097#M110830</link>
      <description>&lt;PRE&gt;data work.want;
   set work.have;
   by x;  /* assumes data is sorted by this variable
             automatic variables for variables on the 
             by statement are available to indicate the 
             first or last of a group represented by 
             the variable(s)
           */

   length Y_List $ 100; /* specify a length of the target variable
                           long enough to hold the longest expected
                           result
                        */
   retain Y_List;       /* keep the value of the variable between iterations
                           of the data step
                        */

   if first.x then Y_List = ' ';  /* set the target variable to empty at 
                                     the start of each group of X values
                                  */
   Y_List = catx(',', Y_List, Y); /* catx function combines the previous version of the
                                     Y_list variable with the current inserting a comma
                                     note the comma only appears BETWEEN values, not after
                                     the last
                                  */
   if last.x then output;       /* the IF in this form only sends data to the output 
                                   set when the condition is true. The condition
                                   here is that the current X value is the last 
                                   of this group.
                                 */

   drop y;                      /* remove the current value of Y when the data is output*/
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 23:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-rows-and-creata-a-new-column-with-values-in-comma/m-p/443097#M110830</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-06T23:47:08Z</dc:date>
    </item>
  </channel>
</rss>

