<?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: How to compute a moving average within a by group? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437944#M282260</link>
    <description>Just to confirm. The following code creates a weighted average within each weight class. This is computed as ?(lot wgt x price) ÷ ?(lot wgt)?&lt;BR /&gt;proc means data=feedercombined_2;&lt;BR /&gt;class Wgt300399;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt300399;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc means data=feedercombined_2;&lt;BR /&gt;class Wgt400499;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt400499;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc means data=feedercombined_2;&lt;BR /&gt;class Wgt500599;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt500599;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;&lt;BR /&gt;proc means data=feedercombined_2;&lt;BR /&gt;class Wgt600699;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt600699;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;&lt;BR /&gt;proc means data=feedercombined_2;&lt;BR /&gt;class Wgt700799;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt700799;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 16 Feb 2018 11:55:55 GMT</pubDate>
    <dc:creator>Mike15</dc:creator>
    <dc:date>2018-02-16T11:55:55Z</dc:date>
    <item>
      <title>How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437312#M282250</link>
      <description>&lt;P&gt;I have data sorted into 100 lb weight groups. Within each group I would like to compute a weighted average price. The formula is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(sum of (Lot weight x price)) / sum of Lot weight&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I compute this value for each weight group.&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 20:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437312#M282250</guid>
      <dc:creator>Mike15</dc:creator>
      <dc:date>2018-02-14T20:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437313#M282251</link>
      <description>&lt;P&gt;PROC MEANS will do this, use the WEIGHT variable to specify the weights and CLASS to specify the groupings.&amp;nbsp;&lt;BR /&gt;If you need more help post your code.&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/193446"&gt;@Mike15&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have data sorted into 100 lb weight groups. Within each group I would like to compute a weighted average price. The formula is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(sum of (Lot weight x price)) / sum of Lot weight&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I compute this value for each weight group.&amp;nbsp; Thank you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 20:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437313#M282251</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-14T20:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437314#M282252</link>
      <description>PS Your description doesn't sound like a moving average, just a weighted average. Or is it a combination of both?</description>
      <pubDate>Wed, 14 Feb 2018 20:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437314#M282252</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-14T20:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437387#M282253</link>
      <description>It's a weighted average, not a moving average. In Excel, I would use "sumproduct" to add up all of the prices. See attachment and below for an example.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;A&lt;BR /&gt;&lt;BR /&gt;B&lt;BR /&gt;&lt;BR /&gt;1&lt;BR /&gt;&lt;BR /&gt;Lot weight&lt;BR /&gt;&lt;BR /&gt;Price&lt;BR /&gt;&lt;BR /&gt;2&lt;BR /&gt;&lt;BR /&gt;664&lt;BR /&gt;&lt;BR /&gt;0.89&lt;BR /&gt;&lt;BR /&gt;3&lt;BR /&gt;&lt;BR /&gt;2676&lt;BR /&gt;&lt;BR /&gt;0.83&lt;BR /&gt;&lt;BR /&gt;4&lt;BR /&gt;&lt;BR /&gt;501&lt;BR /&gt;&lt;BR /&gt;0.79&lt;BR /&gt;&lt;BR /&gt;5&lt;BR /&gt;&lt;BR /&gt;566&lt;BR /&gt;&lt;BR /&gt;0.66&lt;BR /&gt;&lt;BR /&gt;6&lt;BR /&gt;&lt;BR /&gt;420&lt;BR /&gt;&lt;BR /&gt;0.74&lt;BR /&gt;&lt;BR /&gt;7&lt;BR /&gt;&lt;BR /&gt;1775&lt;BR /&gt;&lt;BR /&gt;0.91&lt;BR /&gt;&lt;BR /&gt;8&lt;BR /&gt;&lt;BR /&gt;2283&lt;BR /&gt;&lt;BR /&gt;1.07&lt;BR /&gt;&lt;BR /&gt;9&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;10&lt;BR /&gt;&lt;BR /&gt;Wtd Price&lt;BR /&gt;&lt;BR /&gt;0.89&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Formula: =SUMPRODUCT(A2:A8,B2:B8)/SUM(A2:A8)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Feb 2018 01:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437387#M282253</guid>
      <dc:creator>Mike15</dc:creator>
      <dc:date>2018-02-15T01:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437391#M282254</link>
      <description>&lt;P&gt;Then my first answer was correct. Use PROC MEANS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Useless example here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=sashelp.class;
class sex;
var age;
weight weight;&lt;BR /&gt;output out = want mean= weighted_avg;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Feb 2018 01:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437391#M282254</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-15T01:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437399#M282255</link>
      <description>Here's my code. I'm still not following your advice. Mike15&lt;BR /&gt;&lt;BR /&gt;PROC IMPORT OUT= WORK.FEEDERCOMBINED&lt;BR /&gt;DATAFILE= "C:\Users\mjb28\Documents\Research\ExpandingBeefPr&lt;BR /&gt;odAndMarketing\FeederPrice\Statistics\Recent\Data_COMBINED.xlsx"&lt;BR /&gt;DBMS=EXCEL REPLACE;&lt;BR /&gt;RANGE="Combined$";&lt;BR /&gt;GETNAMES=YES;&lt;BR /&gt;MIXED=NO;&lt;BR /&gt;SCANTEXT=YES;&lt;BR /&gt;USEDATE=YES;&lt;BR /&gt;SCANTIME=YES;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;data feedercombined_1;&lt;BR /&gt;set feedercombined;&lt;BR /&gt;&lt;BR /&gt;if color=5 then delete;&lt;BR /&gt;if color=6 then delete;&lt;BR /&gt;if color=7 then delete;&lt;BR /&gt;if color=8 then delete;&lt;BR /&gt;if sex=2 then delete;&lt;BR /&gt;if sex=3 then delete;&lt;BR /&gt;if sex=4 then delete;&lt;BR /&gt;if sex=5 then delete;&lt;BR /&gt;if sex = 6 then delete;&lt;BR /&gt;if sex = 7 then delete;&lt;BR /&gt;if sex = 8 then delete;&lt;BR /&gt;if sex = 9 then delete;&lt;BR /&gt;&lt;BR /&gt;If PreCond=0 then delete;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;data feedercombined_2;&lt;BR /&gt;set feedercombined_1;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If AvgWgt&amp;lt;300 then delete;&lt;BR /&gt;If AvgWgt&amp;gt;799 then delete;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 300) AND (avgwgt le 399) then Wgt300399=1; else Wgt300399=0;&lt;BR /&gt;if avgwgt=. then Wgt300399=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 400) AND (avgwgt le 499) then Wgt400499=1; else Wgt400499=0;&lt;BR /&gt;if avgwgt=. then Wgt400499=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 500) AND (avgwgt le 599) then Wgt500599=1; else Wgt500599=0;&lt;BR /&gt;if avgwgt=. then Wgt500599=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 600) AND (avgwgt le 699) then Wgt600699=1; else Wgt600699=0;&lt;BR /&gt;if avgwgt=. then Wgt600699=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 700) AND (avgwgt le 799) then Wgt700799=1; else Wgt700799=0;&lt;BR /&gt;if avgwgt=. then Wgt700799=.;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;avgwgt=lotwgt/nohead;&lt;BR /&gt;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Proc print Data=feedercombined_2;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Feb 2018 01:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437399#M282255</guid>
      <dc:creator>Mike15</dc:creator>
      <dc:date>2018-02-15T01:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437409#M282256</link>
      <description>&lt;P&gt;Did you run the code? &amp;nbsp;Which parts don't you understand?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC MEANS prepares summary statistics, so it will summarize your data and apply the weights to the summary.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarding your code (data &lt;SPAN&gt;feedercombined_1)&lt;/SPAN&gt;&amp;nbsp;you can simplify it using IN. These two lines will replace your block of IF regarding color and sex.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if color in (5:8) then delete;
if sex in (2:9) then delete;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or replace both with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if color in (5:8)
   OR sex in (2:9)
   OR PreCond=0 then delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 03:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437409#M282256</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-15T03:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437593#M282257</link>
      <description>I'm doing something wrong, b/c now I get the message&lt;BR /&gt;&lt;BR /&gt;NOTE: There were 2742 observations read from the data set WORK.FEEDERCOMBINED_1.&lt;BR /&gt;&lt;BR /&gt;NOTE: The data set WORK.FEEDERCOMBINED_2 has 0 observations and 25 variables.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;PROC IMPORT OUT= WORK.FEEDERCOMBINED&lt;BR /&gt;DATAFILE= "C:\Users\mjb28\Documents\Research\ExpandingBeefPr&lt;BR /&gt;odAndMarketing\FeederPrice\Statistics\Recent\Data_COMBINED.xlsx"&lt;BR /&gt;DBMS=EXCEL REPLACE;&lt;BR /&gt;RANGE="Combined$";&lt;BR /&gt;GETNAMES=YES;&lt;BR /&gt;MIXED=NO;&lt;BR /&gt;SCANTEXT=YES;&lt;BR /&gt;USEDATE=YES;&lt;BR /&gt;SCANTIME=YES;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;data feedercombined_1;&lt;BR /&gt;set feedercombined;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if color in (5:8)&lt;BR /&gt;OR sex in (2:9)&lt;BR /&gt;OR PreCond=0 then delete;&lt;BR /&gt;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Proc print data=feedercombined_1;&lt;BR /&gt;&lt;BR /&gt;data feedercombined_2;&lt;BR /&gt;set feedercombined_1;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If AvgWgt&amp;lt;300 then delete;&lt;BR /&gt;If AvgWgt&amp;gt;799 then delete;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 300) AND (avgwgt le 399) then Wgt300399=1; else Wgt300399=0;&lt;BR /&gt;if avgwgt=. then Wgt300399=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 400) AND (avgwgt le 499) then Wgt400499=1; else Wgt400499=0;&lt;BR /&gt;if avgwgt=. then Wgt400499=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 500) AND (avgwgt le 599) then Wgt500599=1; else Wgt500599=0;&lt;BR /&gt;if avgwgt=. then Wgt500599=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 600) AND (avgwgt le 699) then Wgt600699=1; else Wgt600699=0;&lt;BR /&gt;if avgwgt=. then Wgt600699=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 700) AND (avgwgt le 799) then Wgt700799=1; else Wgt700799=0;&lt;BR /&gt;if avgwgt=. then Wgt700799=.;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;avgwgt=lotwgt/nohead;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;proc means data=feedercombined_2;&lt;BR /&gt;class avgwgt;&lt;BR /&gt;var price;&lt;BR /&gt;weight avgwgt;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Proc print Data=feedercombined_2;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 15 Feb 2018 14:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437593#M282257</guid>
      <dc:creator>Mike15</dc:creator>
      <dc:date>2018-02-15T14:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437648#M282258</link>
      <description>&lt;P&gt;That's happening in the next step which doesn't change anything in the code I suggested. The error here is in the logic not aligning with the data or your expectations of whats in the data, not the code. The code is syntaxtically correct.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would start by removing the statements in the data step that creates FeederCombined_2 and add them back one by one to see which one is causing the issue or unexpected behaviour.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 15:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437648#M282258</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-15T15:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437655#M282259</link>
      <description>&lt;P&gt;Also, this can't be correct:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;proc means data=feedercombined_2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;class avgwgt; &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&amp;lt;- this is your grouping variable, ie I want analysis by each sex or region;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;var price;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;weight avgwgt; &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&amp;lt;- this is the weight variable, it should not be the same as the CLASS variable;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output out = want mean= weighted_avg;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 15:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437655#M282259</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-15T15:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437944#M282260</link>
      <description>Just to confirm. The following code creates a weighted average within each weight class. This is computed as ?(lot wgt x price) ÷ ?(lot wgt)?&lt;BR /&gt;proc means data=feedercombined_2;&lt;BR /&gt;class Wgt300399;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt300399;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc means data=feedercombined_2;&lt;BR /&gt;class Wgt400499;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt400499;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc means data=feedercombined_2;&lt;BR /&gt;class Wgt500599;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt500599;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;&lt;BR /&gt;proc means data=feedercombined_2;&lt;BR /&gt;class Wgt600699;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt600699;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;&lt;BR /&gt;proc means data=feedercombined_2;&lt;BR /&gt;class Wgt700799;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt700799;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Feb 2018 11:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/437944#M282260</guid>
      <dc:creator>Mike15</dc:creator>
      <dc:date>2018-02-16T11:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438007#M282261</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Just to confirm. The following code creates a weighted average within each weight class. This is computed as ?(lot wgt x price) ÷ ?(lot wgt)?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I don't think that's correct. Please see my comments in my previous post.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 16:01:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438007#M282261</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-16T16:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438027#M282262</link>
      <description>So I took a subset of the data and calculated the weighted average to compare to SAS output. The code runs, but the SAS ouput is the straight mean of price not the weighted average of price. For example within one class (300399) there are 3 lots of cattle; each with different weights and price per lot. I want to know the total weighted average price.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;PROC IMPORT OUT= WORK.TestFall2016&lt;BR /&gt;DATAFILE= "C:\Users\mjb28\Documents\Research\ExpandingBeefPr&lt;BR /&gt;odAndMarketing\FeederPrice\Statistics\Recent\TestFall2016.xlsx"&lt;BR /&gt;DBMS=excel REPLACE;&lt;BR /&gt;GETNAMES=yes;&lt;BR /&gt;&lt;BR /&gt;RUN;&lt;BR /&gt;Proc print; run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data TestFall2016_1;&lt;BR /&gt;set TestFall2016;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if color in (5:8)&lt;BR /&gt;OR sex in (2:9)&lt;BR /&gt;OR PreCond=0 then delete;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data TestFall2016_2;&lt;BR /&gt;set TestFall2016_1;&lt;BR /&gt;&lt;BR /&gt;avgwgt=lotwgt/nohead;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If AvgWgt&amp;lt;300 then delete;&lt;BR /&gt;If AvgWgt&amp;gt;799 then delete;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 300) AND (avgwgt le 399) then Wgt300399=1; else Wgt300399=0;&lt;BR /&gt;if avgwgt=. then Wgt300399=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 400) AND (avgwgt le 499) then Wgt400499=1; else Wgt400499=0;&lt;BR /&gt;if avgwgt=. then Wgt400499=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 500) AND (avgwgt le 599) then Wgt500599=1; else Wgt500599=0;&lt;BR /&gt;if avgwgt=. then Wgt500599=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 600) AND (avgwgt le 699) then Wgt600699=1; else Wgt600699=0;&lt;BR /&gt;if avgwgt=. then Wgt600699=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 700) AND (avgwgt le 799) then Wgt700799=1; else Wgt700799=0;&lt;BR /&gt;if avgwgt=. then Wgt700799=.;&lt;BR /&gt;&lt;BR /&gt;Proc print data=testfall2016_2;&lt;BR /&gt;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;proc means data=testfall2016_2;&lt;BR /&gt;class Wgt300399;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt300399;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc means data=testfall2016_2;&lt;BR /&gt;class Wgt400499;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt400499;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc means data=testfall2016_2;&lt;BR /&gt;class Wgt500599;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt500599;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;&lt;BR /&gt;proc means data=testfall2016_2;&lt;BR /&gt;class Wgt600699;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt600699;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;&lt;BR /&gt;proc means data=testfall2016_2;&lt;BR /&gt;class Wgt700799;&lt;BR /&gt;var price;&lt;BR /&gt;weight Wgt700799;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Feb 2018 17:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438027#M282262</guid>
      <dc:creator>Mike15</dc:creator>
      <dc:date>2018-02-16T17:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438029#M282263</link>
      <description>&lt;P&gt;Your proc means is incorrect, it doesn't make sense to have the CLASS and WEIGHT be the same. Maybe the third times the charm.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 17:31:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438029#M282263</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-16T17:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438038#M282264</link>
      <description>&lt;P&gt;&lt;SPAN&gt;This may be what you want:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;proc means data=testfall2016_2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;class Wgt300399;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;var price;&lt;/SPAN&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;weight avgwgt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;SPAN&gt;output out = want mean= weighted_avg;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 18:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438038#M282264</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-16T18:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438042#M282265</link>
      <description>No, sorry. Still the straight mean.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Feb 2018 18:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438042#M282265</guid>
      <dc:creator>Mike15</dc:creator>
      <dc:date>2018-02-16T18:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438060#M282266</link>
      <description>&lt;P&gt;Then you need to post sample data now.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It does not need to be your real data, but the structure and type should be the same.&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/193446"&gt;@Mike15&lt;/a&gt; wrote:&lt;BR /&gt;No, sorry. Still the straight mean.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 20:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438060#M282266</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-16T20:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438065#M282267</link>
      <description>What's best way to send you the data?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Feb 2018 20:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438065#M282267</guid>
      <dc:creator>Mike15</dc:creator>
      <dc:date>2018-02-16T20:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438067#M282268</link>
      <description>&lt;P&gt;Put it here&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 20:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438067#M282268</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-16T20:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute a moving average within a by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438135#M282269</link>
      <description>data Testfall2016;&lt;BR /&gt;input Date LotWgt NoHead AvgWt Price;&lt;BR /&gt;cards;&lt;BR /&gt;&lt;BR /&gt;10/15/2016 314 1 314 1.13&lt;BR /&gt;10/15/2016 317 1 317 1.10&lt;BR /&gt;10/15/2016 384 1 384 1.26&lt;BR /&gt;10/15/2016 771 2 386 0.94&lt;BR /&gt;10/15/2016 2374 6 396 1.22&lt;BR /&gt;10/15/2016 399 1 399 1.20&lt;BR /&gt;10/15/2016 4239 10 424 1.28&lt;BR /&gt;10/15/2016 428 1 428 1.19&lt;BR /&gt;10/15/2016 874 2 437 1.22&lt;BR /&gt;10/15/2016 2629 6 438 1.20&lt;BR /&gt;10/15/2016 911 2 456 1.15&lt;BR /&gt;10/15/2016 2401 5 480 1.28&lt;BR /&gt;10/15/2016 3400 7 486 1.26&lt;BR /&gt;10/15/2016 2026 4 507 1.23&lt;BR /&gt;10/15/2016 1030 2 515 1.17&lt;BR /&gt;10/15/2016 524 1 524 0.82&lt;BR /&gt;10/15/2016 3309 6 552 1.21&lt;BR /&gt;10/15/2016 4604 8 576 1.20&lt;BR /&gt;10/15/2016 1183 2 592 0.79&lt;BR /&gt;10/15/2016 1297 2 649 1.00&lt;BR /&gt;10/15/2016 4678 7 668 1.20&lt;BR /&gt;10/15/2016 685 1 685 0.99&lt;BR /&gt;10/15/2016 743 1 743 0.96&lt;BR /&gt;10/15/2016 4706 6 784 1.16&lt;BR /&gt;10/15/2016 3149 4 787 1.03&lt;BR /&gt;RUN;&lt;BR /&gt;Proc print; run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data TestFall2016_1;&lt;BR /&gt;set TestFall2016;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if color in (5:8)&lt;BR /&gt;OR sex in (2:9)&lt;BR /&gt;OR PreCond=0 then delete;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data TestFall2016_2;&lt;BR /&gt;set TestFall2016_1;&lt;BR /&gt;&lt;BR /&gt;avgwgt=lotwgt/nohead;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If AvgWgt&amp;lt;300 then delete;&lt;BR /&gt;If AvgWgt&amp;gt;799 then delete;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 300) AND (avgwgt le 399) then Wgt300399=1; else Wgt300399=0;&lt;BR /&gt;if avgwgt=. then Wgt300399=.;&lt;BR /&gt;&lt;BR /&gt;if (avgwgt ge 700) AND (avgwgt le 799) then Wgt700799=1; else Wgt700799=0;&lt;BR /&gt;if avgwgt=. then Wgt700799=.;&lt;BR /&gt;&lt;BR /&gt;Proc print data=testfall2016_2;&lt;BR /&gt;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;proc means data=testfall2016_2;&lt;BR /&gt;class Wgt300399;&lt;BR /&gt;var price;&lt;BR /&gt;weight avgwgt;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc means data=testfall2016_2;&lt;BR /&gt;class Wgt700799;&lt;BR /&gt;var price;&lt;BR /&gt;weight avgwgt;&lt;BR /&gt;output out = want mean= weighted_avg;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=testfall2016_3;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 17 Feb 2018 10:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compute-a-moving-average-within-a-by-group/m-p/438135#M282269</guid>
      <dc:creator>Mike15</dc:creator>
      <dc:date>2018-02-17T10:07:55Z</dc:date>
    </item>
  </channel>
</rss>

