<?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 Sum and Group by in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654064#M196474</link>
    <description>&lt;P&gt;I've the data as follows and I want to calculate the variable 'LOBS' and the calculation should be like&lt;EM&gt; sum(PREM) group by Segment and ID / DIV value by Segment.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;It means sum of PREM by Segment and ID and divide by DIV of respective Segment value. Is there a way that we do this calculation in one step (data or proc sql)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For DIV we have Input values based on SEGMENT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data step is below with the sample data.&lt;/P&gt;
&lt;PRE&gt;data&amp;nbsp;have;
input&amp;nbsp;ID SEGMENT $ PREM DIV;
datalines;
1000 NL 0.124 0.327
1000 HS 0.187 0.567
1000 HS 0.098 0.567
1100 NL 0.123 0.327
1100 NL 0.175 0.327
1100 NL 0.123 0.327
1100 HS 0.342 0.567
1100 HS 0.126 0.567
;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jun 2020 06:14:50 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2020-06-08T06:14:50Z</dc:date>
    <item>
      <title>Sum and Group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654064#M196474</link>
      <description>&lt;P&gt;I've the data as follows and I want to calculate the variable 'LOBS' and the calculation should be like&lt;EM&gt; sum(PREM) group by Segment and ID / DIV value by Segment.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;It means sum of PREM by Segment and ID and divide by DIV of respective Segment value. Is there a way that we do this calculation in one step (data or proc sql)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For DIV we have Input values based on SEGMENT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data step is below with the sample data.&lt;/P&gt;
&lt;PRE&gt;data&amp;nbsp;have;
input&amp;nbsp;ID SEGMENT $ PREM DIV;
datalines;
1000 NL 0.124 0.327
1000 HS 0.187 0.567
1000 HS 0.098 0.567
1100 NL 0.123 0.327
1100 NL 0.175 0.327
1100 NL 0.123 0.327
1100 HS 0.342 0.567
1100 HS 0.126 0.567
;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 06:14:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654064#M196474</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-06-08T06:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and Group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654066#M196476</link>
      <description>&lt;P&gt;Yes. Both are possible. Provide usable data in the form of a data step to recieve a usable code answer.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 21:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654066#M196476</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-06-07T21:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and Group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654092#M196496</link>
      <description>In the meantime can I know the logic to accomplish it?&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Jun 2020 03:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654092#M196496</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-06-08T03:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and Group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654104#M196506</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;- Data step is below with the sample data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ID SEGMENT $ PREM DIV;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1000 NL 0.124 0.327&lt;/P&gt;
&lt;P&gt;1000 HS 0.187 0.567&lt;/P&gt;
&lt;P&gt;1000 HS 0.098 0.567&lt;/P&gt;
&lt;P&gt;1100 NL 0.123 0.327&lt;/P&gt;
&lt;P&gt;1100 NL 0.175 0.327&lt;/P&gt;
&lt;P&gt;1100 NL 0.123 0.327&lt;/P&gt;
&lt;P&gt;1100 HS 0.342 0.567&lt;/P&gt;
&lt;P&gt;1100 HS 0.126 0.567&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 06:15:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654104#M196506</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-06-08T06:15:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and Group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654132#M196508</link>
      <description>&lt;P&gt;I guess your second dataline is incorrect, as it creates an ambiguous value of DIV for segment NL.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Data step is below with the sample data.&lt;/P&gt;
&lt;PRE&gt;data&amp;nbsp;have;
input&amp;nbsp;ID SEGMENT $ PREM DIV;
datalines;
1000 NL 0.124 0.327
1000 NL 0.125 0.567
1000 HS 0.187 0.567
1000 HS 0.098 0.567
1100 NL 0.123 0.327
1100 NL 0.175 0.327
1100 NL 0.123 0.327
1100 HS 0.342 0.567
1100 HS 0.126 0.567
;
run;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 05:37:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654132#M196508</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-08T05:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and Group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654163#M196509</link>
      <description>That's fine. You can remove the incorrect entry. I'm looking for logic to&lt;BR /&gt;implement it.&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Jun 2020 06:06:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654163#M196509</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-06-08T06:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and Group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654179#M196510</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;Corrected the data now in initial post.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 06:16:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654179#M196510</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-06-08T06:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: Sum and Group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654225#M196513</link>
      <description>&lt;P&gt;Then it would be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    *,
    sum(prem) / div
  from have
  group by id, segment
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested, posted from my tablet)&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 06:59:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sum-and-Group-by/m-p/654225#M196513</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-08T06:59:22Z</dc:date>
    </item>
  </channel>
</rss>

