<?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 data with BY statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Grouping-data-with-BY-statement/m-p/351625#M273752</link>
    <description>&lt;P&gt;Thanks Kurt for your recommendation. The code worked fine.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Apr 2017 11:44:53 GMT</pubDate>
    <dc:creator>Uknown_user</dc:creator>
    <dc:date>2017-04-20T11:44:53Z</dc:date>
    <item>
      <title>Grouping data with BY statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-data-with-BY-statement/m-p/351584#M273748</link>
      <description>&lt;PRE&gt;DATA TMP;
SET NOV_TRX;
BY PK_CONSUMER_ID;
IF FIRST.PK_CONSUMER_ID THEN TOTAL_VOLUME = 0;
TOTAL_VOLUME + SALES_QUANTITY;
IF LAST.PK_CONSUMER_ID THEN OUTPUT;
RUN;&lt;/PRE&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to group&amp;nbsp;a piece of data set&amp;nbsp;(please see the attachement that representes a sample of my data). The code I wrote so far provides me with TOTAL_VOLUME per consumer, however, I would also need the volume per customer and&amp;nbsp;VP_MG as well as volume per customer and Diesel_Petrol but do not know how to amend it code so that it worked. Thanks for suggestions.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 09:09:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-data-with-BY-statement/m-p/351584#M273748</guid>
      <dc:creator>Uknown_user</dc:creator>
      <dc:date>2017-04-20T09:09:04Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping data with BY statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-data-with-BY-statement/m-p/351596#M273749</link>
      <description>&lt;P&gt;Look at PROC MEANS, specifically look at the CLASS, WAYS, TYPES statements.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 10:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-data-with-BY-statement/m-p/351596#M273749</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-20T10:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping data with BY statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-data-with-BY-statement/m-p/351606#M273750</link>
      <description>&lt;P&gt;Thanks for your suggestion, I might take a look at it later. I would like to manage it just with BY statement right now which I believe should be very easy.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 10:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-data-with-BY-statement/m-p/351606#M273750</guid>
      <dc:creator>Uknown_user</dc:creator>
      <dc:date>2017-04-20T10:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping data with BY statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-data-with-BY-statement/m-p/351621#M273751</link>
      <description>&lt;P&gt;DO NOT post SAS data in an Excel file. An Excel spreadsheet contains no metadata information (variable length, assigned formats etc) which is crucial for understanding your issues.&lt;/P&gt;
&lt;P&gt;Instead use the macro provided in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; to convert your dataset into a data step that can be posted here in a code window. This allows to exactly recreate your dataset with copy/paste and run, and since only text is involved, firewalls won't block this. (I can't download Excel files from the internet where my SAS is available, because the company firewall blocks them for security reasons; the same is true for many contributors here)&lt;/P&gt;
&lt;P&gt;Since you have two different subgroups, you will need two steps if you use data step logic:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data
  sum_total (keep=pk_customer_id total_volume)
  sum_vp_mg (keep=pk_customer_id vp_mg vp_mg_volume)
;
set nov_trx;
by pk_customer_id vp_mg;
if first.pk_customer_id then total_volume = 0;
if first.vp_mg then vp_mg_volume = 0;
total_volume + sales_quantity;
vp_mg_volume + sales_quantity;
if last.vp_mg then output sum_vp_mg;
if last.pk_customer_id then output sum_total;
run;

data sum_diesel_petrol (keep=pk_customer_id diesel_petrol dp_volume);
set nov_trx;
by pk_customer_id diesel_petrol;
if first.diesel_petrol then dp_volume = 0;
dp_volume + sales_quantity;
if last.diesel_petrol then output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Apr 2017 11:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-data-with-BY-statement/m-p/351621#M273751</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-20T11:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping data with BY statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-data-with-BY-statement/m-p/351625#M273752</link>
      <description>&lt;P&gt;Thanks Kurt for your recommendation. The code worked fine.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 11:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-data-with-BY-statement/m-p/351625#M273752</guid>
      <dc:creator>Uknown_user</dc:creator>
      <dc:date>2017-04-20T11:44:53Z</dc:date>
    </item>
  </channel>
</rss>

