<?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 recursive mean error in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/recursive-mean-error/m-p/687335#M79581</link>
    <description>&lt;P&gt;hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did not find my error in this program. there is no error in the log but the output did not do any calculation&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input code DATe : yymmdd10. variation;* recursive mean;&lt;BR /&gt;format date yymmdd10.;&lt;BR /&gt;cards;&lt;BR /&gt;1 2020-01-02 -1.35&lt;BR /&gt;1 2020-01-03 -1.48&lt;BR /&gt;1 2020-01-06 2.40&lt;BR /&gt;1 2020-01-07 -0.85&lt;BR /&gt;1 2020-01-08 -0.24&lt;BR /&gt;1 2020-01-09 2.49&lt;BR /&gt;1 2020-01-10 1.68&lt;BR /&gt;1 2020-01-13 -1.69&lt;BR /&gt;1 2020-01-14 -0.91&lt;BR /&gt;1 2020-01-15 -0.93&lt;BR /&gt;1 2020-01-16 2.71&lt;BR /&gt;1 2020-01-17 -0.05&lt;BR /&gt;1 2020-01-20 1.69&lt;BR /&gt;1 2020-01-21 -3.64&lt;BR /&gt;1 2020-01-22 1.24&lt;BR /&gt;1 2020-01-23 -2.05&lt;BR /&gt;1 2020-01-24 -2.97&lt;BR /&gt;1 2020-01-27 -0.78&lt;BR /&gt;1 2020-01-28 3.09;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select a.code,a.date,a.variation,ifn(count(*)=11,mean(b.variation),.) as rec_mean format=8.4&lt;BR /&gt;from ind a left join ind b&lt;/P&gt;
&lt;P&gt;on a.code=b.code and intnx('day',a.DATE,-12)&amp;lt;= b.DATE&amp;lt;=intnx('day',a.DATE,-2)&lt;BR /&gt;group by a.code,a.date,a.variation&lt;BR /&gt;order by a.code,a.date;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 20:08:00 GMT</pubDate>
    <dc:creator>sasphd</dc:creator>
    <dc:date>2020-09-28T20:08:00Z</dc:date>
    <item>
      <title>recursive mean error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/recursive-mean-error/m-p/687335#M79581</link>
      <description>&lt;P&gt;hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did not find my error in this program. there is no error in the log but the output did not do any calculation&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input code DATe : yymmdd10. variation;* recursive mean;&lt;BR /&gt;format date yymmdd10.;&lt;BR /&gt;cards;&lt;BR /&gt;1 2020-01-02 -1.35&lt;BR /&gt;1 2020-01-03 -1.48&lt;BR /&gt;1 2020-01-06 2.40&lt;BR /&gt;1 2020-01-07 -0.85&lt;BR /&gt;1 2020-01-08 -0.24&lt;BR /&gt;1 2020-01-09 2.49&lt;BR /&gt;1 2020-01-10 1.68&lt;BR /&gt;1 2020-01-13 -1.69&lt;BR /&gt;1 2020-01-14 -0.91&lt;BR /&gt;1 2020-01-15 -0.93&lt;BR /&gt;1 2020-01-16 2.71&lt;BR /&gt;1 2020-01-17 -0.05&lt;BR /&gt;1 2020-01-20 1.69&lt;BR /&gt;1 2020-01-21 -3.64&lt;BR /&gt;1 2020-01-22 1.24&lt;BR /&gt;1 2020-01-23 -2.05&lt;BR /&gt;1 2020-01-24 -2.97&lt;BR /&gt;1 2020-01-27 -0.78&lt;BR /&gt;1 2020-01-28 3.09;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select a.code,a.date,a.variation,ifn(count(*)=11,mean(b.variation),.) as rec_mean format=8.4&lt;BR /&gt;from ind a left join ind b&lt;/P&gt;
&lt;P&gt;on a.code=b.code and intnx('day',a.DATE,-12)&amp;lt;= b.DATE&amp;lt;=intnx('day',a.DATE,-2)&lt;BR /&gt;group by a.code,a.date,a.variation&lt;BR /&gt;order by a.code,a.date;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/recursive-mean-error/m-p/687335#M79581</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2020-09-28T20:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: recursive mean error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/recursive-mean-error/m-p/687336#M79582</link>
      <description>hello, &lt;BR /&gt;&lt;BR /&gt;I did not find my error in this program. there is no error in the log but the output did not do any calculation&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;data ind;&lt;BR /&gt;input code DATe : yymmdd10. variation;* recursive mean;&lt;BR /&gt;format date yymmdd10.;&lt;BR /&gt;cards;&lt;BR /&gt;1 2020-01-02 -1.35&lt;BR /&gt;1 2020-01-03 -1.48&lt;BR /&gt;1 2020-01-06 2.40&lt;BR /&gt;1 2020-01-07 -0.85&lt;BR /&gt;1 2020-01-08 -0.24&lt;BR /&gt;1 2020-01-09 2.49&lt;BR /&gt;1 2020-01-10 1.68&lt;BR /&gt;1 2020-01-13 -1.69&lt;BR /&gt;1 2020-01-14 -0.91&lt;BR /&gt;1 2020-01-15 -0.93&lt;BR /&gt;1 2020-01-16 2.71&lt;BR /&gt;1 2020-01-17 -0.05&lt;BR /&gt;1 2020-01-20 1.69&lt;BR /&gt;1 2020-01-21 -3.64&lt;BR /&gt;1 2020-01-22 1.24&lt;BR /&gt;1 2020-01-23 -2.05&lt;BR /&gt;1 2020-01-24 -2.97&lt;BR /&gt;1 2020-01-27 -0.78&lt;BR /&gt;1 2020-01-28 3.09;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select a.code,a.date,a.variation,ifn(count(*)=11,mean(b.variation),.) as rec_mean format=8.4&lt;BR /&gt;from ind a left join ind b&lt;BR /&gt;&lt;BR /&gt;on a.code=b.code and intnx('day',a.DATE,-12)&amp;lt;= b.DATE&amp;lt;=intnx('day',a.DATE,-2)&lt;BR /&gt;group by a.code,a.date,a.variation&lt;BR /&gt;order by a.code,a.date;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/recursive-mean-error/m-p/687336#M79582</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2020-09-28T20:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: recursive mean error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/recursive-mean-error/m-p/687338#M79583</link>
      <description>How does IFN() work in SQL? Would it work on the aggregated data or the row level data?&lt;BR /&gt;&lt;BR /&gt;I'm going to guess that's the issue. I would recommend a data step instead or PROC EXPAND if you have the SAS/ETS license.&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;array p{0:3} _temporary_;&lt;BR /&gt;set have; &lt;BR /&gt;by object;&lt;BR /&gt;if first.object then do; call missing(of p{*}); count=0; end;&lt;BR /&gt;count+1;&lt;BR /&gt;p{mod(_n_,4)} = price;&lt;BR /&gt;if count &amp;gt;4 then lowest = min(of p{*});&lt;BR /&gt;if count &amp;gt; 4 then highest = max(of p{*});&lt;BR /&gt;run;</description>
      <pubDate>Mon, 28 Sep 2020 20:13:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/recursive-mean-error/m-p/687338#M79583</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-28T20:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: recursive mean error</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/recursive-mean-error/m-p/687343#M79584</link>
      <description>&lt;P&gt;thanks reeza&lt;/P&gt;
&lt;P&gt;but INF works here!!!!!&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data have;
input GVKEY	DATADATE : yymmdd10.	TRT1M;*	recursive mean;
format datadate yymmdd10.;
cards;
001081	2004-01-31	-1.8322	 
001081	2004-02-29	4.3713	 
001081	2004-03-31	-11.9811	 
001081	2004-04-30	2.8939	 
001081	2004-05-31	2.2396	 
001081	2004-06-30	-6.5373	 
001081	2004-07-31	-4.6448	 
001081	2004-08-31	-10.4598	 
001081	2004-09-30	2.0539	 
001081	2004-10-31	-8.2390	 
001081	2004-11-30	10.0413	 
001081	2004-12-31	3.2500	 
001081	2005-01-31	-18.2809	-2.01
001081	2005-02-28	-14.8889	-1.55
001081	2005-03-31	-2.0979	-3.61
001096	2004-01-31	-4.0816	 
001096	2004-02-29	4.6809	 
001096	2004-03-31	-2.8862	 
001096	2004-04-30	-3.1579	 
001096	2004-05-31	-1.0870	 
001096	2004-06-30	2.8132	 
001096	2004-07-31	-3.2258	 
001096	2004-08-31	3.3333	 
001096	2004-09-30	4.9032	 
001096	2004-10-31	1.6495	 
001096	2004-11-30	5.4767	 
001096	2004-12-31	0.7308	 
001096	2005-01-31	1.7274	0.77
001096	2005-02-28	2.0755	1.20
;
proc sql;
create table want as
select a.gvkey,a.datadate,a.TRT1M,ifn(count(*)=11,mean(b.TRT1M),.) as rec_mean format=8.2
from have a left join have b
on a.gvkey=b.gvkey and intnx('mon',a.DATADATE,-12,'e')&amp;lt;= b.DATADATE&amp;lt;=intnx('mon',a.DATADATE,-2,'e')
group by a.gvkey,a.datadate,a.TRT1M
order by  a.gvkey,a.datadate;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/recursive-mean-error/m-p/687343#M79584</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2020-09-28T20:47:01Z</dc:date>
    </item>
  </channel>
</rss>

