<?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 moving sum over N observations and require at least M of them to be nonmissing? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-moving-sum-over-N-observations-and-require-at-least-M/m-p/829272#M327623</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/99650"&gt;@xyxu&lt;/a&gt;&amp;nbsp;agree. Proc Expand is so short and smooth &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Aug 2022 19:07:23 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-08-18T19:07:23Z</dc:date>
    <item>
      <title>Calculate moving sum over N observations and require at least M of them to be nonmissing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-moving-sum-over-N-observations-and-require-at-least-M/m-p/829141#M327569</link>
      <description>&lt;P&gt;Let's say N=8 and M= 6. If the number of non-missing values within a rolling window is fewer than 6, the program should set the output value to be missing. Not sure if the following does this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc expand data = have out = want method = none;
	by firm;
	id date;
	convert x = y/ transformout = (movsum 8 trimleft 5);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2022 03:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-moving-sum-over-N-observations-and-require-at-least-M/m-p/829141#M327569</guid>
      <dc:creator>xyxu</dc:creator>
      <dc:date>2022-08-18T03:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate moving sum over N observations and require at least M of them to be nonmissing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-moving-sum-over-N-observations-and-require-at-least-M/m-p/829152#M327574</link>
      <description>&lt;P&gt;I'm not entirely sure here, but I don't think Proc Expand has such an option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want an alternative to Proc Expand?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2022 06:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-moving-sum-over-N-observations-and-require-at-least-M/m-p/829152#M327574</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-18T06:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate moving sum over N observations and require at least M of them to be nonmissing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-moving-sum-over-N-observations-and-require-at-least-M/m-p/829176#M327581</link>
      <description>&lt;PRE&gt;/*Assuming there is no gap between dates*/
data have;
call streaminit(123);
do firm='A' ,'B' ,'C';
  do date='01jan2010'd to '20dec2021'd;
   x=rand('uniform');output;
  end;
end;
format date date9.;
run;


%let n=8;
%let m=6;
data want;
   set have;
   by firm;
 array t{0:%eval(&amp;amp;n.-1)} _temporary_;
if first.firm then do; n=0; call missing(of t{*});end;
n+1;
t{mod(n,&amp;amp;n.)}=x;
if n ge &amp;amp;n. and n(of t{*}) ge &amp;amp;m. then moving_mean=mean(of t{*});
drop n;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2022 12:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-moving-sum-over-N-observations-and-require-at-least-M/m-p/829176#M327581</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-08-18T12:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate moving sum over N observations and require at least M of them to be nonmissing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-moving-sum-over-N-observations-and-require-at-least-M/m-p/829268#M327620</link>
      <description>Thanks for confirming that proc expand cannot do this. There are definitely (less elegant) solutions.</description>
      <pubDate>Thu, 18 Aug 2022 18:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-moving-sum-over-N-observations-and-require-at-least-M/m-p/829268#M327620</guid>
      <dc:creator>xyxu</dc:creator>
      <dc:date>2022-08-18T18:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate moving sum over N observations and require at least M of them to be nonmissing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-moving-sum-over-N-observations-and-require-at-least-M/m-p/829272#M327623</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/99650"&gt;@xyxu&lt;/a&gt;&amp;nbsp;agree. Proc Expand is so short and smooth &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2022 19:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-moving-sum-over-N-observations-and-require-at-least-M/m-p/829272#M327623</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-08-18T19:07:23Z</dc:date>
    </item>
  </channel>
</rss>

