<?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 Group by Issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Group-by-Issue/m-p/147729#M297514</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Im trying to obtain a summary and provide a total for each variable by rep. The problem im having is that this code still brings back all records, however the average and and totals are correct but it displays the same numeric for each record. Any idea why it wont display 1 row with the totals?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;create table work.redemptions_summary as&lt;BR /&gt;select &lt;BR /&gt;a.month_date,&lt;BR /&gt;repay_Type as Rep &lt;BR /&gt;count(*) as count,&lt;BR /&gt;avg (a.i_tv) as Ave_tv,&lt;BR /&gt;avg (a.bal_o) as Average_Bal,&lt;BR /&gt;avg (b.cii) as cii,&lt;BR /&gt;avg (b.deli) as del,&lt;BR /&gt;count(*) as red_vol,&lt;BR /&gt;sum(bal_out) as red_bal,&lt;BR /&gt;sum(case when Rep= 'Cap' then bal_out else 0 end) as cap,&lt;BR /&gt;sum(case when Rep= 'Int' then bal_out else 0 end) as int,&lt;BR /&gt;sum(case when Rep= 'Mixed' then bal_out else 0 end) as part,&lt;BR /&gt;sum(bal_out)as Total_Bal,&lt;BR /&gt;case &lt;BR /&gt;when remaining_months &amp;lt;= 1 then 'End'&lt;BR /&gt;when remaining_months &amp;lt;= 12 then 'OP'&lt;BR /&gt;when arr_stage_code ne 'ZZ' then 'Ar' &lt;BR /&gt;else 'Rem' end as Red_rea&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from &lt;BR /&gt;work.red as a&lt;BR /&gt;left join work.red_stats as b &lt;BR /&gt;on a.anm = b.aco&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where &lt;BR /&gt;platform = 'um'&lt;BR /&gt;and Arr_stage_code not in ('4','5','6')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;group by &lt;BR /&gt;rep,&lt;/P&gt;&lt;P&gt;month_date;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 04 Aug 2014 13:26:11 GMT</pubDate>
    <dc:creator>anonymous_user</dc:creator>
    <dc:date>2014-08-04T13:26:11Z</dc:date>
    <item>
      <title>Group by Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-Issue/m-p/147729#M297514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Im trying to obtain a summary and provide a total for each variable by rep. The problem im having is that this code still brings back all records, however the average and and totals are correct but it displays the same numeric for each record. Any idea why it wont display 1 row with the totals?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;create table work.redemptions_summary as&lt;BR /&gt;select &lt;BR /&gt;a.month_date,&lt;BR /&gt;repay_Type as Rep &lt;BR /&gt;count(*) as count,&lt;BR /&gt;avg (a.i_tv) as Ave_tv,&lt;BR /&gt;avg (a.bal_o) as Average_Bal,&lt;BR /&gt;avg (b.cii) as cii,&lt;BR /&gt;avg (b.deli) as del,&lt;BR /&gt;count(*) as red_vol,&lt;BR /&gt;sum(bal_out) as red_bal,&lt;BR /&gt;sum(case when Rep= 'Cap' then bal_out else 0 end) as cap,&lt;BR /&gt;sum(case when Rep= 'Int' then bal_out else 0 end) as int,&lt;BR /&gt;sum(case when Rep= 'Mixed' then bal_out else 0 end) as part,&lt;BR /&gt;sum(bal_out)as Total_Bal,&lt;BR /&gt;case &lt;BR /&gt;when remaining_months &amp;lt;= 1 then 'End'&lt;BR /&gt;when remaining_months &amp;lt;= 12 then 'OP'&lt;BR /&gt;when arr_stage_code ne 'ZZ' then 'Ar' &lt;BR /&gt;else 'Rem' end as Red_rea&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from &lt;BR /&gt;work.red as a&lt;BR /&gt;left join work.red_stats as b &lt;BR /&gt;on a.anm = b.aco&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where &lt;BR /&gt;platform = 'um'&lt;BR /&gt;and Arr_stage_code not in ('4','5','6')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;group by &lt;BR /&gt;rep,&lt;/P&gt;&lt;P&gt;month_date;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2014 13:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-Issue/m-p/147729#M297514</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2014-08-04T13:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Group by Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-Issue/m-p/147730#M297515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would imagine that its to do with the case statement creating a unique value for each of the rows.&amp;nbsp;&amp;nbsp; You can try putting select distinct to start, and also remove the case statement.&amp;nbsp; You should then get one row per by group.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2014 13:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-Issue/m-p/147730#M297515</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-08-04T13:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Group by Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-Issue/m-p/147731#M297516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just bring case statement under group by with an aggregate function.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2014 14:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-Issue/m-p/147731#M297516</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-08-04T14:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Group by Issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-Issue/m-p/147732#M297517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to aggregate your case statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2014 14:40:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-Issue/m-p/147732#M297517</guid>
      <dc:creator>Keith0001</dc:creator>
      <dc:date>2014-08-04T14:40:18Z</dc:date>
    </item>
  </channel>
</rss>

