<?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: Grouping observations using one by variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-using-one-by-variable/m-p/769568#M244044</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;Why a grouping is not happening if I don't bring first and last in grouping? What is the role of first and last?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First and last create the grouping. If you don't have it, then no grouping is created because there is no code to do that grouping.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FIRST.DEPT sets the sum to zero each time DEPT changes. LAST.DEPT is used to control which records are output, only the last record for each value of DEPT is output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I always recommend that you don't do summing (or computing most other statistics) by group in a DATA step, because SAS has already written that code for you in PROC MEANS/PROC SUMMARY. Really, don't do this in a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=temp nway;
    class dept;
    var payroll;
    output out=sums sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Sep 2021 17:15:11 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-09-22T17:15:11Z</dc:date>
    <item>
      <title>Grouping observations using one by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-using-one-by-variable/m-p/769388#M244039</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;Why a grouping is not happening if I don't bring first and last in grouping? What is the role of first and last?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc sort data=cert.usa out=work.temp;
by dept;
run;
data work.budget (Keep = dept payroll);
set work.temp;
by dept;
if wagecate = 'S' then yearly = wagerate*12;
else if wagecat='H" then yearly = wagerate*2000;
if first.dept then payroll=0;
payroll+yearly;
if last.dept;
Run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Sep 2021 16:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-using-one-by-variable/m-p/769388#M244039</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-09-22T16:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping observations using one by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-using-one-by-variable/m-p/769391#M244040</link>
      <description>&lt;P&gt;What do you mean by "&lt;SPAN&gt;grouping is not happening" ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 16:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-using-one-by-variable/m-p/769391#M244040</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-09-22T16:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping observations using one by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-using-one-by-variable/m-p/769568#M244044</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;Why a grouping is not happening if I don't bring first and last in grouping? What is the role of first and last?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First and last create the grouping. If you don't have it, then no grouping is created because there is no code to do that grouping.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FIRST.DEPT sets the sum to zero each time DEPT changes. LAST.DEPT is used to control which records are output, only the last record for each value of DEPT is output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I always recommend that you don't do summing (or computing most other statistics) by group in a DATA step, because SAS has already written that code for you in PROC MEANS/PROC SUMMARY. Really, don't do this in a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=temp nway;
    class dept;
    var payroll;
    output out=sums sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 17:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-using-one-by-variable/m-p/769568#M244044</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-22T17:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping observations using one by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-using-one-by-variable/m-p/769638#M244056</link>
      <description>&lt;P&gt;Maxim 1: Read the Documentation.&lt;/P&gt;
&lt;P&gt;See&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lestmtsref/p0yeyftk8ftuckn1o5qzy53284gz.htm#p0z2v37ykk47i8n171lzad8fyrvg" target="_blank" rel="noopener"&gt;How SAS Identifies the Beginning and End of a BY Group&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/lrcon/9.4/n138da4gme3zb7n1nifpfhqv7clq.htm" target="_blank" rel="noopener"&gt;BY-Group Processing in the DATA Step&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 18:20:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-observations-using-one-by-variable/m-p/769638#M244056</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-22T18:20:22Z</dc:date>
    </item>
  </channel>
</rss>

