<?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: How to CONCAN by Group in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792024#M253769</link>
    <description>&lt;P&gt;Here are two ways:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_blank" rel="noopener"&gt;https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: That SQL will remerge with original table though, giving you 1 record per observation as the first calculation is row level, not an aggregate calculation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ORACLE would error out I believe.&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/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Try to CONCAN string into a line. Oracle has group_concan(). How to do it in SAS/SQL? Anyone&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table summ_peek as&lt;BR /&gt;select case when cylinders&amp;gt;=6 then 1 else 0 end as flag, count(*) as cttot, concan(make) as make&lt;BR /&gt;from sashelp.cars&lt;BR /&gt;group by 1;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jan 2022 23:59:04 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-01-24T23:59:04Z</dc:date>
    <item>
      <title>How to CONCAN by Group in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792023#M253768</link>
      <description>&lt;P&gt;Try to CONCAN string into a line. Oracle has group_concan(). How to do it in SAS/SQL? Anyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table summ_peek as&lt;BR /&gt;select case when cylinders&amp;gt;=6 then 1 else 0 end as flag, count(*) as cttot, concan(make) as make&lt;BR /&gt;from sashelp.cars&lt;BR /&gt;group by 1;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 23:51:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792023#M253768</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-01-24T23:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to CONCAN by Group in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792024#M253769</link>
      <description>&lt;P&gt;Here are two ways:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_blank" rel="noopener"&gt;https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: That SQL will remerge with original table though, giving you 1 record per observation as the first calculation is row level, not an aggregate calculation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ORACLE would error out I believe.&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/409584"&gt;@hellohere&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Try to CONCAN string into a line. Oracle has group_concan(). How to do it in SAS/SQL? Anyone&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table summ_peek as&lt;BR /&gt;select case when cylinders&amp;gt;=6 then 1 else 0 end as flag, count(*) as cttot, concan(make) as make&lt;BR /&gt;from sashelp.cars&lt;BR /&gt;group by 1;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 23:59:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792024#M253769</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-24T23:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to CONCAN by Group in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792025#M253770</link>
      <description>&lt;P&gt;Do you mind to Cut-&amp;amp;-Paste the webpage( text only is fine)? I cannot access that webpage. Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 00:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792025#M253770</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-01-25T00:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to CONCAN by Group in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792039#M253776</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create sample data for demonstration;
data have;
    infile cards dlm='09'x;
    input OrgID Product $   States $;
    cards;
1   football    DC
1   football    VA
1   football    MD
2   football    CA
3   football    NV
3   football    CA
;
run;

*Sort - required for both options;
proc sort data=have;
    by orgID;
run;

**********************************************************************;
*Use RETAIN and BY group processing to combine the information;
**********************************************************************;
data want_option1;
    set have;
    by orgID;
    length combined $100.;
    retain combined;

    if first.orgID then
        combined=states;
    else
        combined=catx(', ', combined, states);

    if last.orgID then
        output;
run;

**********************************************************************;
*Transpose it to a wide format and then combine into a single field;
**********************************************************************;
proc transpose data=have out=wide prefix=state_;
    by orgID;
    var states;
run;

data want_option2;
    set wide;
    length combined $100.;
    combined=catx(', ', of state_:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jan 2022 01:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792039#M253776</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-01-25T01:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to CONCAN by Group in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792045#M253779</link>
      <description>thanks</description>
      <pubDate>Tue, 25 Jan 2022 01:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792045#M253779</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-01-25T01:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to CONCAN by Group in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792145#M253807</link>
      <description>&lt;P&gt;The first solution suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;can be made a bit simpler (and slightly faster) like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_option1;
  do until(last.orgID);   
    set have;
    by orgID;
    length combined $100.;
    call catx(', ', combined, states);&lt;BR /&gt;    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And it has to be done in a data step, because SAS SQL does not have concatenation as a "summary" function, unlike most other SQL dialects.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If performance matters, you should always use CALL CATX rather than the function.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 10:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-CONCAN-by-Group-in-SAS/m-p/792145#M253807</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-01-25T10:40:12Z</dc:date>
    </item>
  </channel>
</rss>

