<?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 Horizontal summation of observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511856#M137764</link>
    <description>&lt;P&gt;I modified data into a new data set to look like this;&lt;/P&gt;&lt;P&gt;ID Trans Sales&lt;/P&gt;&lt;P&gt;01 1 $135.00&lt;BR /&gt;01 1 $75.00&lt;BR /&gt;01 1 $140.00&lt;BR /&gt;01 2 $140.00&lt;BR /&gt;02 1 $220.00&lt;BR /&gt;03 1 $135.00&lt;BR /&gt;03 1 $125.00&lt;BR /&gt;03 2 $80.00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to sum the sales by the ID. I hit a wall and would appreciate any feedback as I am stuck on how to properly syntax summing sales by ID. Here is my code I have that attempts that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data employee_sales;
merge datain.sales datain.parts;
by part_no;
if quantity = . then delete;
drop part_no price quantity;
sales= quantity*price;
total_sales= SUM(sales);
run;
proc sort;
by descending ID ;
run;
proc print data=employee_sales noobs;
format ID z2. sales dollar8.2 ;
title 'Employee Sales';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and the output for that&lt;/P&gt;&lt;P&gt;ID trans sales total_sales&lt;BR /&gt;03 1 $135.00 135&lt;BR /&gt;03 1 $125.00 125&lt;BR /&gt;03 2 $80.00 80&lt;BR /&gt;02 1 $220.00 220&lt;BR /&gt;01 1 $135.00 135&lt;BR /&gt;01 1 $75.00 75&lt;BR /&gt;01 1 $140.00 140&lt;BR /&gt;01 2 $140.00 140&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It just repeats itself, does anyone have any idea what I am doing wrong?&lt;/P&gt;</description>
    <pubDate>Fri, 09 Nov 2018 22:13:58 GMT</pubDate>
    <dc:creator>clancaster</dc:creator>
    <dc:date>2018-11-09T22:13:58Z</dc:date>
    <item>
      <title>Horizontal summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511856#M137764</link>
      <description>&lt;P&gt;I modified data into a new data set to look like this;&lt;/P&gt;&lt;P&gt;ID Trans Sales&lt;/P&gt;&lt;P&gt;01 1 $135.00&lt;BR /&gt;01 1 $75.00&lt;BR /&gt;01 1 $140.00&lt;BR /&gt;01 2 $140.00&lt;BR /&gt;02 1 $220.00&lt;BR /&gt;03 1 $135.00&lt;BR /&gt;03 1 $125.00&lt;BR /&gt;03 2 $80.00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to sum the sales by the ID. I hit a wall and would appreciate any feedback as I am stuck on how to properly syntax summing sales by ID. Here is my code I have that attempts that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data employee_sales;
merge datain.sales datain.parts;
by part_no;
if quantity = . then delete;
drop part_no price quantity;
sales= quantity*price;
total_sales= SUM(sales);
run;
proc sort;
by descending ID ;
run;
proc print data=employee_sales noobs;
format ID z2. sales dollar8.2 ;
title 'Employee Sales';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and the output for that&lt;/P&gt;&lt;P&gt;ID trans sales total_sales&lt;BR /&gt;03 1 $135.00 135&lt;BR /&gt;03 1 $125.00 125&lt;BR /&gt;03 2 $80.00 80&lt;BR /&gt;02 1 $220.00 220&lt;BR /&gt;01 1 $135.00 135&lt;BR /&gt;01 1 $75.00 75&lt;BR /&gt;01 1 $140.00 140&lt;BR /&gt;01 2 $140.00 140&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It just repeats itself, does anyone have any idea what I am doing wrong?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 22:13:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511856#M137764</guid>
      <dc:creator>clancaster</dc:creator>
      <dc:date>2018-11-09T22:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Horizontal summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511857#M137765</link>
      <description>&lt;P&gt;what do you mean by&amp;nbsp;&lt;SPAN&gt;Horizontal summation?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I am unable to understand your expected output&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I could see the sales dataset and where's the parts dataset&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 22:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511857#M137765</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-09T22:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Horizontal summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511858#M137766</link>
      <description>&lt;P&gt;Unfortunately you have the wrong approach. SUM will sum all values within a ROW, not in a column. You want PROC MEANS.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a quick example on how it works, the last one includes one that has a grouping variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/243371"&gt;@clancaster&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I modified data into a new data set to look like this;&lt;/P&gt;
&lt;P&gt;ID Trans Sales&lt;/P&gt;
&lt;P&gt;01 1 $135.00&lt;BR /&gt;01 1 $75.00&lt;BR /&gt;01 1 $140.00&lt;BR /&gt;01 2 $140.00&lt;BR /&gt;02 1 $220.00&lt;BR /&gt;03 1 $135.00&lt;BR /&gt;03 1 $125.00&lt;BR /&gt;03 2 $80.00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have to sum the sales by the ID. I hit a wall and would appreciate any feedback as I am stuck on how to properly syntax summing sales by ID. Here is my code I have that attempts that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data employee_sales;
merge datain.sales datain.parts;
by part_no;
if quantity = . then delete;
drop part_no price quantity;
sales= quantity*price;
total_sales= SUM(sales);
run;
proc sort;
by descending ID ;
run;
proc print data=employee_sales noobs;
format ID z2. sales dollar8.2 ;
title 'Employee Sales';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the output for that&lt;/P&gt;
&lt;P&gt;ID trans sales total_sales&lt;BR /&gt;03 1 $135.00 135&lt;BR /&gt;03 1 $125.00 125&lt;BR /&gt;03 2 $80.00 80&lt;BR /&gt;02 1 $220.00 220&lt;BR /&gt;01 1 $135.00 135&lt;BR /&gt;01 1 $75.00 75&lt;BR /&gt;01 1 $140.00 140&lt;BR /&gt;01 2 $140.00 140&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It just repeats itself, does anyone have any idea what I am doing wrong?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 22:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511858#M137766</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-09T22:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: Horizontal summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511860#M137767</link>
      <description>&lt;P&gt;you have provided only 1 table as incoming data, and you are using a merge why?&lt;/P&gt;
&lt;P&gt;Please provide better detail and code that represents the data samples you provide.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 22:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511860#M137767</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-09T22:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: Horizontal summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511867#M137770</link>
      <description>Oh thanks for the insight</description>
      <pubDate>Fri, 09 Nov 2018 22:44:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511867#M137770</guid>
      <dc:creator>clancaster</dc:creator>
      <dc:date>2018-11-09T22:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Horizontal summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511871#M137773</link>
      <description>&lt;P&gt;If you want total sales by ID then cannot do it in a data step that sorted by PART_NO.&lt;/P&gt;
&lt;P&gt;You can use RETAIN and SUM(total_sales,sales).&amp;nbsp; Or just use a sum STATEMENT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data employee_sales_raw;
  merge datain.sales datain.parts;
  by part_no;
  if quantity = . then delete;
  drop part_no price quantity;
  sales= quantity*price;
run;
proc sort;
  by id descending;
run;
data employee_sales ;
  set employee_sales_raw ;
  by id descending ;
  total_sales + sales ;
  if first.id then total_sales=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Nov 2018 23:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511871#M137773</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-09T23:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Horizontal summation of observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511967#M137820</link>
      <description>&lt;P&gt;Thank you. This helps quite a bit.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Nov 2018 19:50:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Horizontal-summation-of-observations/m-p/511967#M137820</guid>
      <dc:creator>clancaster</dc:creator>
      <dc:date>2018-11-10T19:50:22Z</dc:date>
    </item>
  </channel>
</rss>

