<?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: Calculate multiple averages on same column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-multiple-averages-on-same-column/m-p/260463#M50545</link>
    <description>&lt;P&gt;Use a data step view and create new variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   if '17OCT2011'd le date le '28NOV2011'd then do;
      str_4_D1 = str_4;
      end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 31 Mar 2016 16:20:36 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2016-03-31T16:20:36Z</dc:date>
    <item>
      <title>Calculate multiple averages on same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-multiple-averages-on-same-column/m-p/260458#M50543</link>
      <description>&lt;P&gt;I'm hoping to find&amp;nbsp;some method which will allow me to calculate multiple averages on the same columns for different time periods, and I'm not sure how or if it can be done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some example data would be as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  format Date mmddyy10.;
  input Date STR_3 STR_4 STR_7 STR_8;
  datalines;
  18917 . 17386 . 6756
  18924 . 20913 . 9101
  18931 . 19672 . 8734
  18938 . 20362 . 9175
  18945 . 21325 . 8749
  18952 . 21129 . 8932
  18959 . 21540 . 8374
  18966 17714 19860 . 9645
  18973 14983 22248 . 9055
  18981 12833 20781 . 8709
  18988 17347 21402 . 8886
  18995 17295 22218 4400 9738
  19002 17337 21577 3813 8830
  19009 17402 23090 5052 10119
  19016 17395 23426 5001 9480
  19024 14114 24574 4361 9702
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And it looks like this:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2572iF3ECCDA97A8EB65B/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;Let's say I want to do the following:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Calculate an average of all observations for STR_3.&lt;/LI&gt;
&lt;LI&gt;Calculate an average, using STR_4, for the period 10/17/2011 through 11/28/2011.&lt;/LI&gt;
&lt;LI&gt;Calculate an average, using STR_4, for the period 12/05/2011 through 02/01/2012.&lt;/LI&gt;
&lt;LI&gt;Calculate an average of all observations for STR_7.&lt;/LI&gt;
&lt;LI&gt;Calculate an average, using STR_8, for the period 10/17/2011 through 12/27/2011.&lt;/LI&gt;
&lt;LI&gt;Calculate an average, using STR_8, for the period 01/03/2012 through 02/01/2012.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;It would seem I'm not clever enough to come up with some method, or I'm unaware of a procedure that would allow me to do something like that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone have any suggestions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 16:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-multiple-averages-on-same-column/m-p/260458#M50543</guid>
      <dc:creator>KyleM_Corrie</dc:creator>
      <dc:date>2016-03-31T16:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate multiple averages on same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-multiple-averages-on-same-column/m-p/260463#M50545</link>
      <description>&lt;P&gt;Use a data step view and create new variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   if '17OCT2011'd le date le '28NOV2011'd then do;
      str_4_D1 = str_4;
      end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2016 16:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-multiple-averages-on-same-column/m-p/260463#M50545</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-03-31T16:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate multiple averages on same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-multiple-averages-on-same-column/m-p/260464#M50546</link>
      <description>&lt;P&gt;One way is to calculate all combinations and then filter out what you don't want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  format Date mmddyy10.;
  input Date STR_3 STR_4 STR_7 STR_8;

  if  '17Oct2011'd &amp;lt; Date &amp;lt; '28Nov2011'd then group4=1;
  else if '05Dec2011'd &amp;lt;Date &amp;lt;'01Feb2012'd then group4=2;

  if  '17Oct2011'd &amp;lt; Date &amp;lt; '27Dec2011'd then group8=1;
  else if '03Jan2012'd &amp;lt; Date &amp;lt; '01Feb2012'd then group8=2;

  datalines;
  18917 . 17386 . 6756
  18924 . 20913 . 9101
  18931 . 19672 . 8734
  18938 . 20362 . 9175
  18945 . 21325 . 8749
  18952 . 21129 . 8932
  18959 . 21540 . 8374
  18966 17714 19860 . 9645
  18973 14983 22248 . 9055
  18981 12833 20781 . 8709
  18988 17347 21402 . 8886
  18995 17295 22218 4400 9738
  19002 17337 21577 3813 8830
  19009 17402 23090 5052 10119
  19016 17395 23426 5001 9480
  19024 14114 24574 4361 9702
  ;
run;

title;
proc means data=have mean missing stackods;
class group4 group8;
var str_3 str_7 str_4 str_7;
ods output summary=want;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 16:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-multiple-averages-on-same-column/m-p/260464#M50546</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-31T16:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate multiple averages on same column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-multiple-averages-on-same-column/m-p/260595#M50595</link>
      <description>&lt;PRE&gt;


data have;
  format Date mmddyy10.;
  input Date STR_3 STR_4 STR_7 STR_8;
  datalines;
  18917 . 17386 . 6756
  18924 . 20913 . 9101
  18931 . 19672 . 8734
  18938 . 20362 . 9175
  18945 . 21325 . 8749
  18952 . 21129 . 8932
  18959 . 21540 . 8374
  18966 17714 19860 . 9645
  18973 14983 22248 . 9055
  18981 12833 20781 . 8709
  18988 17347 21402 . 8886
  18995 17295 22218 4400 9738
  19002 17337 21577 3813 8830
  19009 17402 23090 5052 10119
  19016 17395 23426 5001 9480
  19024 14114 24574 4361 9702
  ;
run;
proc sql;
select 
(select mean(STR_3) from have) as mean_STR_3,
(select mean(STR_4) from have where STR_3 is missing) as mean1_STR_4,
(select mean(STR_4) from have where STR_3 is not missing) as mean2_STR_4,
(select mean(STR_7) from have) as mean_STR_7,
(select mean(STR_8) from have where STR_7 is missing) as mean1_STR_8,
(select mean(STR_8) from have where STR_7 is not missing) as mean2_STR_8
from have(obs=1);
quit;

&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Apr 2016 02:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-multiple-averages-on-same-column/m-p/260595#M50595</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-01T02:34:55Z</dc:date>
    </item>
  </channel>
</rss>

