<?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 excluding observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-excluding-observations/m-p/7838#M178</link>
    <description>and if your data were too huge for that cartesian join, you could use proc MEANS to get grand, followed by class totals, and digest that summary:[pre]&lt;BR /&gt;
proc means noprint data= huge_data ;&lt;BR /&gt;
   class job ;&lt;BR /&gt;
   var   count hours ;&lt;BR /&gt;
   output sum= ;&lt;BR /&gt;
run ;&lt;BR /&gt;
data digested ;&lt;BR /&gt;
   set ;&lt;BR /&gt;
   retain g1-g2 ;&lt;BR /&gt;
   if _type_ = 0 then do;&lt;BR /&gt;
      g1= count ;&lt;BR /&gt;
      g2= hours ;&lt;BR /&gt;
      delete ;&lt;BR /&gt;
   end ;&lt;BR /&gt;
   count1 = g1 - count ;&lt;BR /&gt;
   hours1 = g2 - hours ;&lt;BR /&gt;
   keep job count1 hours1 ;&lt;BR /&gt;
run ;[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
Of course, huge is not specific, but I think the cartesian join in SQL will run out of resources before proc MEANS.&lt;BR /&gt;
 &lt;BR /&gt;
any bets?&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
    <pubDate>Fri, 23 Apr 2010 09:32:15 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2010-04-23T09:32:15Z</dc:date>
    <item>
      <title>sum excluding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-excluding-observations/m-p/7835#M175</link>
      <description>I have three variables: job, count, hours.&lt;BR /&gt;
There are more than 100 observations.&lt;BR /&gt;
The data looks like this: &lt;BR /&gt;
&lt;BR /&gt;
job        count hours&lt;BR /&gt;
welder1      10   100&lt;BR /&gt;
plumber      11   110&lt;BR /&gt;
lineman      9    120&lt;BR /&gt;
construction 5    90&lt;BR /&gt;
welder2      11   200&lt;BR /&gt;
&lt;BR /&gt;
I would like to create two new variables count1 and hours1.&lt;BR /&gt;
For each job I would like to sum count (ie count1) and sum hours (ie hours1) without including that particular job.&lt;BR /&gt;
For example, for welder1 I would have count1=11+9+5+11 and hours1=110+120+90+200.&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your help.</description>
      <pubDate>Thu, 22 Apr 2010 03:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-excluding-observations/m-p/7835#M175</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2010-04-22T03:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: sum excluding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-excluding-observations/m-p/7836#M176</link>
      <description>I think this suits SQL pretty well.&lt;BR /&gt;
But maybe in a way it isn't usually used, by re-merging summaries to the original data.&lt;BR /&gt;
Maybe not to be recommended if you have huge data.&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select *, sum(count) - count as count1, sum(hours) - hours as hours1&lt;BR /&gt;
from MyInputTable;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Thu, 22 Apr 2010 07:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-excluding-observations/m-p/7836#M176</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2010-04-22T07:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: sum excluding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-excluding-observations/m-p/7837#M177</link>
      <description>Looks good. Thank you.</description>
      <pubDate>Thu, 22 Apr 2010 16:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-excluding-observations/m-p/7837#M177</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2010-04-22T16:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: sum excluding observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-excluding-observations/m-p/7838#M178</link>
      <description>and if your data were too huge for that cartesian join, you could use proc MEANS to get grand, followed by class totals, and digest that summary:[pre]&lt;BR /&gt;
proc means noprint data= huge_data ;&lt;BR /&gt;
   class job ;&lt;BR /&gt;
   var   count hours ;&lt;BR /&gt;
   output sum= ;&lt;BR /&gt;
run ;&lt;BR /&gt;
data digested ;&lt;BR /&gt;
   set ;&lt;BR /&gt;
   retain g1-g2 ;&lt;BR /&gt;
   if _type_ = 0 then do;&lt;BR /&gt;
      g1= count ;&lt;BR /&gt;
      g2= hours ;&lt;BR /&gt;
      delete ;&lt;BR /&gt;
   end ;&lt;BR /&gt;
   count1 = g1 - count ;&lt;BR /&gt;
   hours1 = g2 - hours ;&lt;BR /&gt;
   keep job count1 hours1 ;&lt;BR /&gt;
run ;[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
Of course, huge is not specific, but I think the cartesian join in SQL will run out of resources before proc MEANS.&lt;BR /&gt;
 &lt;BR /&gt;
any bets?&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Fri, 23 Apr 2010 09:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-excluding-observations/m-p/7838#M178</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-04-23T09:32:15Z</dc:date>
    </item>
  </channel>
</rss>

