<?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: Dropping a group while taking the mean in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837467#M331115</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Making huge assumptions that you're doing it by date and want to add the mean to the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table summary as
select date, group, var_a, sum(case when group ne 0 then var_a else 0 end)/sum(case when group ne 0 then 1 else 0 end) as avg_minus_group0
from have
group by date
order by 1, 2, 3;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This does not give a correct answer if one or more values of var_a is missing. PROC MEANS, on the other hand, gives the correct answer if one or more values of var_a is missing.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Oct 2022 21:39:58 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-10-07T21:39:58Z</dc:date>
    <item>
      <title>Dropping a group while taking the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837447#M331104</link>
      <description>&lt;P&gt;Dear All:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;My SAS Data is as follows&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Group&amp;nbsp; &amp;nbsp; Var_A&lt;/P&gt;&lt;P&gt;&amp;nbsp; 02OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22&lt;/P&gt;&lt;P&gt;&amp;nbsp; 02OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 28&lt;/P&gt;&lt;P&gt;02OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;33&lt;/P&gt;&lt;P&gt;03OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;55&lt;/P&gt;&lt;P&gt;03OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 75&lt;/P&gt;&lt;P&gt;03OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 86&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to take the mean of VAR_A by excluding Group 0 from the calculation.&amp;nbsp; There is a long method of doing this by creating a new data set excluding 0.&amp;nbsp; Is there a shorter way to do this so that I can preserve the data set.&lt;/P&gt;&lt;P&gt;Thanks much&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 18:10:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837447#M331104</guid>
      <dc:creator>RandyStan</dc:creator>
      <dc:date>2022-10-07T18:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Dropping a group while taking the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837451#M331106</link>
      <description>&lt;P&gt;One way to get the mean, or other statistics, would be:&lt;/P&gt;
&lt;PRE&gt;Proc Means data=have mean;
   where group ne 0;
   var var_a;
run;&lt;/PRE&gt;
&lt;P&gt;IF you want a data set you should provide what you want as a result as there are a number of ways to do this but specifics may change based on desired content.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 19:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837451#M331106</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-07T19:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Dropping a group while taking the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837452#M331107</link>
      <description>Getting the means is easy.  PROC steps support the WHERE statement:&lt;BR /&gt;&lt;BR /&gt;proc means data=have;&lt;BR /&gt;var var_a;&lt;BR /&gt;where group ne 0;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;You still have to decide whether you want a separate mean for each date, and whether you want to merge the results back into the original data.</description>
      <pubDate>Fri, 07 Oct 2022 19:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837452#M331107</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-10-07T19:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Dropping a group while taking the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837460#M331110</link>
      <description>&lt;P&gt;Making huge assumptions that you're doing it by date and want to add the mean to the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table summary as
select date, group, var_a, sum(case when group ne 0 then var_a else 0 end)/sum(case when group ne 0 then 1 else 0 end) as avg_minus_group0
from have
group by date
order by 1, 2, 3;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133090"&gt;@RandyStan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear All:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;My SAS Data is as follows&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Group&amp;nbsp; &amp;nbsp; Var_A&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 02OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 02OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 28&lt;/P&gt;
&lt;P&gt;02OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;33&lt;/P&gt;
&lt;P&gt;03OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;55&lt;/P&gt;
&lt;P&gt;03OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 75&lt;/P&gt;
&lt;P&gt;03OCT2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 86&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to take the mean of VAR_A by excluding Group 0 from the calculation.&amp;nbsp; There is a long method of doing this by creating a new data set excluding 0.&amp;nbsp; Is there a shorter way to do this so that I can preserve the data set.&lt;/P&gt;
&lt;P&gt;Thanks much&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 20:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837460#M331110</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-07T20:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Dropping a group while taking the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837467#M331115</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Making huge assumptions that you're doing it by date and want to add the mean to the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table summary as
select date, group, var_a, sum(case when group ne 0 then var_a else 0 end)/sum(case when group ne 0 then 1 else 0 end) as avg_minus_group0
from have
group by date
order by 1, 2, 3;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This does not give a correct answer if one or more values of var_a is missing. PROC MEANS, on the other hand, gives the correct answer if one or more values of var_a is missing.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 21:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837467#M331115</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-07T21:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Dropping a group while taking the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837469#M331117</link>
      <description>Nope, it won't. But OP hasn't explained their requirements well enough. Proc Means is multiple steps and I have the impression they'd like to avoid that....but it's definitely a guess.</description>
      <pubDate>Fri, 07 Oct 2022 21:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837469#M331117</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-07T21:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Dropping a group while taking the mean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837492#M331134</link>
      <description>&lt;P&gt;PROC SQL knows how to take a MEAN also.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select date
     , group
     , var_a
     , mean(case when group ne 0 then var_a else . end) as avg_minus_group0
from have
group by date&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Oct 2022 02:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dropping-a-group-while-taking-the-mean/m-p/837492#M331134</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-08T02:22:02Z</dc:date>
    </item>
  </channel>
</rss>

