<?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: sum by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-by-group/m-p/744585#M233278</link>
    <description>Works good, thanks Angel.</description>
    <pubDate>Sat, 29 May 2021 04:51:35 GMT</pubDate>
    <dc:creator>Ramin1</dc:creator>
    <dc:date>2021-05-29T04:51:35Z</dc:date>
    <item>
      <title>sum by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-by-group/m-p/744561#M233267</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;I want to sum one column based on some criteria and placed the sum value in a designated row. I add the data file here and what I want to get is the following&lt;/P&gt;&lt;P&gt;I want to sum TDC1 column based on gvkey, year, execrankann (execrankann 1 to 5) and want to put the sum value in the row which has value "ceo" in CEO column. For instance;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ruhul_0-1622243862367.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59873iA2F98B550A987FFA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ruhul_0-1622243862367.png" alt="Ruhul_0-1622243862367.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in this case, I want&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ruhul_1-1622244571874.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59874iAB7C496AB40981AE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ruhul_1-1622244571874.png" alt="Ruhul_1-1622244571874.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 23:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-by-group/m-p/744561#M233267</guid>
      <dc:creator>Ramin1</dc:creator>
      <dc:date>2021-05-28T23:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: sum by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-by-group/m-p/744575#M233273</link>
      <description>&lt;P&gt;Try the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=HAVE;  /*order data set to use by statement in data step*/
by GVKEY YEAR EXECRANKANN;
quit;

data pre_want;      /*Creates the cumulative variable (SUM)*/
set HAVE;
by GVKEY YEAR;
if FIRST.YEAR THEN SUM=0;
SUM+TDC1;
run;

proc sql;
create table WANT as        /*Select the sum per group and paste it to the observation with CEOANN = "CEO"*/
select a.*, b.SUM as SUM_5_EXEC
from pre_want as a left join (select YEAR,GVKEY,SUM
							  from pre_want
							  where EXECRANKANN=5) as b

		on  (a.GVKEY=b.GVKEY and a.YEAR=b.YEAR and a.CEOANN="CEO")

order by GVKEY, YEAR, EXECRANKANN    
;
drop table pre_want;  /*Deletes the pre_want table*/
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 May 2021 02:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-by-group/m-p/744575#M233273</guid>
      <dc:creator>Angel_Larrion</dc:creator>
      <dc:date>2021-05-29T02:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: sum by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-by-group/m-p/744585#M233278</link>
      <description>Works good, thanks Angel.</description>
      <pubDate>Sat, 29 May 2021 04:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-by-group/m-p/744585#M233278</guid>
      <dc:creator>Ramin1</dc:creator>
      <dc:date>2021-05-29T04:51:35Z</dc:date>
    </item>
  </channel>
</rss>

