<?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 the average for a [+1,+3} and a [-3,-1] window in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893610#M44269</link>
    <description>Repeat the process BEFORE  the backwards sort to get the values you want.</description>
    <pubDate>Mon, 11 Sep 2023 17:41:38 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2023-09-11T17:41:38Z</dc:date>
    <item>
      <title>calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893594#M44264</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am working for question similar to moving average.&lt;/P&gt;&lt;P&gt;for the first obs #1 value 14, I would like to get the number for average for next three values as (6+3+5)/3&lt;/P&gt;&lt;P&gt;which means a [+1,+3} window for the average.&lt;/P&gt;&lt;P&gt;I looked some of the proc expand command but I did not get a solution.&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;&lt;P&gt;Zhongda&lt;/P&gt;&lt;P&gt;here are the data&lt;/P&gt;&lt;P&gt;# value average for next three values&lt;BR /&gt;1 14 4.666666667 =AVERAGE(B3:B5)&lt;BR /&gt;2 6 7.333333333 =AVERAGE(B4:B6)&lt;BR /&gt;3 3 7.666666667 =AVERAGE(B5:B7)&lt;BR /&gt;4 5 11.66666667 =AVERAGE(B6:B8)&lt;BR /&gt;5 14 9 =AVERAGE(B7:B9)&lt;BR /&gt;6 4 11.33333333 =AVERAGE(B8:B10)&lt;BR /&gt;7 17 10.33333333 =AVERAGE(B9:B11)&lt;BR /&gt;8 6&lt;BR /&gt;9 11&lt;BR /&gt;10 14&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 16:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893594#M44264</guid>
      <dc:creator>Zhongda</dc:creator>
      <dc:date>2023-09-11T16:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893602#M44267</link>
      <description>&lt;P&gt;Is that 1 to 10 actually in the data or just part of an example? If not in the data then one approach is to add an order variable like that, sort the data into reverse order, us the LAG function to get values to calculate the mean. The SAS LAG function looks at previous values but there is no automatic look ahead.&lt;/P&gt;
&lt;P&gt;Don't include spreadsheet cell references as they confuse the issue. Do include example data of what you actually have in the form of a working data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  input v;
  order = _n_;
datalines;
14
6 
3 
5 
14
4 
17
6
11
14
;

proc sort data=have;
by descending order;
run;

data want;
   set have;
   l1=lag1(v);
   l2=lag2(v);
   l3=lag3(v);
   mean = (l1+l2+l3)/3;
   drop l1-l3;
run;

proc sort data=want;
   by order;
run;


&lt;/PRE&gt;
&lt;P&gt;I used the manual mean calculation as your example seems to imply that you do not want the mean unless all three values are non-missing.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 16:49:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893602#M44267</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-11T16:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893603#M44268</link>
      <description>&lt;P&gt;Hi Ballardw,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your solution and it perfectly works for a [+1,+3] window. I would like to ask what if I want to calculate another average for window [-3,-1] for each observation? This means, for the first three obs in the sample, this is NA and it should start from the 4th obs and the value will be calculated as (14+6+3)/3&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;14
6 
3 
5 
14
4 
17
6
11
14&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2023 17:04:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893603#M44268</guid>
      <dc:creator>Zhongda</dc:creator>
      <dc:date>2023-09-11T17:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893610#M44269</link>
      <description>Repeat the process BEFORE  the backwards sort to get the values you want.</description>
      <pubDate>Mon, 11 Sep 2023 17:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893610#M44269</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-09-11T17:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893690#M44276</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 03:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893690#M44276</guid>
      <dc:creator>Zhongda</dc:creator>
      <dc:date>2023-09-12T03:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893691#M44277</link>
      <description>&lt;P&gt;I see this problem is marked as solved, but there is a far more efficient way to get lead values without the triple step of sorting, generating lags, and then resorting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do this as a single step using the &lt;EM&gt;&lt;STRONG&gt;firstobs=&lt;/STRONG&gt;&lt;/EM&gt; option for dataset names, and a conditional merge or conditional set statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input v  @@ ;
datalines;
14    6    3    5   14
 4   17    6   11   14
;

data want (drop=_:);
  set have;
  
  if end_of_leads=0 then 
    merge have (firstobs=2 keep=v rename=(v=_lead1))
          have (firstobs=3 keep=v rename=(v=_lead2))
          have (firstobs=4 keep=v rename=(v=_lead3))
          end=end_of_leads ;
  else call missing(of _lead:);

  if nmiss(of _lead:)=0 then average=mean(of _lead:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This can save a lot of resources when dealing with large datasets.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 04:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893691#M44277</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-12T04:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893693#M44278</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436330"&gt;@Zhongda&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Ballardw,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for your solution and it perfectly works for a [+1,+3] window. I would like to ask what if I want to calculate another average for window [-3,-1] for each observation? This means, for the first three obs in the sample, this is NA and it should start from the 4th obs and the value will be calculated as (14+6+3)/3&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you want to do the average of the 3 preceding obs as well as the 3 following obs, then you can use a combination of (1) lag functions,&amp;nbsp; (2) firstobs= options, and (3) a conditional merge statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input v  @@ ;
datalines;
14    6    3    5   14
 4   17    6   11   14
;

data want ;
  set have;
  
  if end_of_leads=0 then 
    merge have (firstobs=2 keep=v rename=(v=_lead1))
          have (firstobs=3 keep=v rename=(v=_lead2))
          have (firstobs=4 keep=v rename=(v=_lead3))
    end=end_of_leads ;
  else call missing(of _lead:);

  average_preceding=ifn(_n_&amp;gt;=4,mean(lag(v),lag2(v),lag3(v)),.);
  if nmiss(of _lead:)=0 then average_following=mean(of _lead:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note there is a significant difference between using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; average_preceding=ifn(_n_&amp;gt;=4,mean(lag(v),lag2(v),lag3(v)),.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the (likely more intuitive, but wrong)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if _n_&amp;gt;=4 then average_preceding=mean(lag(v),lag2(v),lag3(v));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That's because the lag functions don't look back like an excel spreadsheet, but rather update queues of variable V.&amp;nbsp; And you need to update the queue for every obs, even though you won't use those queue values for observations 1 through 3.&amp;nbsp; &amp;nbsp;The IF statements would fail to update the queues, while the IFN function will update the queue even if the queue values are not chosen iby the IFN condition.&amp;nbsp; &amp;nbsp;But the IFN approach will make the results for observation 4 as expected.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 04:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893693#M44278</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-12T04:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893694#M44279</link>
      <description>&lt;P&gt;Hi mkeintz,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for bringing this issue out.&lt;/P&gt;&lt;P&gt;The code you provide is good but one thing for my working project is that there are different identifier in different years. While I am using proc sort, I can sort the data into group according to each id and year.&lt;/P&gt;&lt;P&gt;then I can apply the ''lag method'' within each group.&lt;/P&gt;&lt;P&gt;I would like to know how can we achieve this in the method you provide.&lt;/P&gt;&lt;P&gt;Here are the sample dataset, and thank you for your time.&lt;/P&gt;&lt;P&gt;my object is to calculate each id a [+1,+3] window and a [-3,-1] window for the average value.&lt;/P&gt;&lt;DIV&gt;id year value&lt;/DIV&gt;&lt;DIV&gt;1 1990 42&lt;/DIV&gt;&lt;DIV&gt;1 1991 16&lt;/DIV&gt;&lt;DIV&gt;1 1992 25&lt;/DIV&gt;&lt;DIV&gt;1 1993 20&lt;/DIV&gt;&lt;DIV&gt;1 1994 34&lt;/DIV&gt;&lt;DIV&gt;1 1995 44&lt;/DIV&gt;&lt;DIV&gt;1 1996 14&lt;/DIV&gt;&lt;DIV&gt;1 1997 35&lt;/DIV&gt;&lt;DIV&gt;1 1998 42&lt;/DIV&gt;&lt;DIV&gt;1 1999 37&lt;/DIV&gt;&lt;DIV&gt;2 1990 36&lt;/DIV&gt;&lt;DIV&gt;2 1991 21&lt;/DIV&gt;&lt;DIV&gt;2 1992 12&lt;/DIV&gt;&lt;DIV&gt;2 1993 40&lt;/DIV&gt;&lt;DIV&gt;2 1994 32&lt;/DIV&gt;&lt;DIV&gt;2 1995 36&lt;/DIV&gt;&lt;DIV&gt;2 1996 31&lt;/DIV&gt;&lt;DIV&gt;2 1997 43&lt;/DIV&gt;&lt;DIV&gt;2 1998 37&lt;/DIV&gt;&lt;DIV&gt;2 1999 33&lt;/DIV&gt;&lt;DIV&gt;3 1990 36&lt;/DIV&gt;&lt;DIV&gt;3 1991 33&lt;/DIV&gt;&lt;DIV&gt;3 1992 30&lt;/DIV&gt;&lt;DIV&gt;3 1993 20&lt;/DIV&gt;&lt;DIV&gt;3 1994 15&lt;/DIV&gt;&lt;DIV&gt;3 1995 34&lt;/DIV&gt;&lt;DIV&gt;3 1996 36&lt;/DIV&gt;&lt;DIV&gt;3 1997 20&lt;/DIV&gt;&lt;DIV&gt;3 1998 37&lt;/DIV&gt;&lt;DIV&gt;3 1999 40&lt;/DIV&gt;</description>
      <pubDate>Tue, 12 Sep 2023 04:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893694#M44279</guid>
      <dc:creator>Zhongda</dc:creator>
      <dc:date>2023-09-12T04:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893832#M44290</link>
      <description>&lt;P&gt;It's better to completely define the problem at the start - otherwise there can be mission-creep-fatigue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BUT ... this is a common problem - getting leads and leads within ID, from a sorted dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id year v  @@;
datalines;
1 1990 42     1 1991 16     1 1992 25     1 1993 20     
1 1994 34     1 1995 44     1 1996 14     1 1997 35     
1 1998 42     1 1999 37     2 1990 36     2 1991 21     
2 1992 12     2 1993 40     2 1994 32     2 1995 36     
2 1996 31     2 1997 43     2 1998 37     2 1999 33     
3 1990 36     3 1991 33     3 1992 30     3 1993 20     
3 1994 15     3 1995 34     3 1996 36     3 1997 20     
3 1998 37     3 1999 40     
run;

data want ;
  set have;
  by id;
  _seq+1;
  if first.id then _seq=1;
  
  if end_of_leads=0 then 
    merge have (firstobs=2 keep=   v rename=(v=_lead1))
          have (firstobs=3 keep=   v rename=(v=_lead2))
          have (firstobs=4 keep=id v rename=(id=_id3 v=_lead3))
    end=end_of_leads ;
  else call missing(of _lead:);
  if _id3^=id then call missing(of _lead:);

  average_preceding=ifn(_seq&amp;gt;=4,mean(lag(v),lag2(v),lag3(v)),.);
  if nmiss(of _lead:)=0 then average_following=mean(of _lead:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The technique for keeping LAGs only from the same ID is uses the _SEQ variable rather than automatic variable _N_.&amp;nbsp; &amp;nbsp;For keeping LEADs within the same ID, you have to check the ID of the farther lead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the BY statement applies only to the SET statement preceding it.&amp;nbsp; There is no BY attached to the MERGE statement.&amp;nbsp; This is essential, because a MERGE with BY will effectively remove the benefit of using the different FIRSTOBS values, once the second ID is encountered.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 15:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893832#M44290</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-12T15:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893847#M44291</link>
      <description>&lt;P&gt;As the problem is solved already I am not going to work on some example code, but if you have SAS/ETS , I would do this using PROC EXPAND or (when specifications are more difficult) PROC TIMEDATA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking ahead with PROC TIMEDATA is really easy !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 16:41:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893847#M44291</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-09-12T16:41:49Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893972#M44298</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;As the problem is solved already I am not going to work on some example code, but if you have SAS/ETS , I would do this using PROC EXPAND or (when specifications are more difficult) PROC TIMEDATA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking ahead with PROC TIMEDATA is really easy !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Looking ahead with the DATA step isn't particularly hard either, at least in this case.&amp;nbsp; And it offers a lot more flexibility than proc expand (except for smoothing).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IMO, the main deficiency with PROC EXPAND is that it only does univariate statistics (means, medians, max, std, etc. for single variables).&amp;nbsp; it doesn't even generate a sums-of-cross-products for a rolling window, which means it is no good for direct application to rolling window regressions - a major disappointment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does PROC TIMEDATA address that issue?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 00:11:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/893972#M44298</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-13T00:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/894189#M44301</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;wrote: Does PROC TIMEDATA address that issue?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&lt;BR /&gt;Have a look at this example :&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/etsug/etsug_timedata_examples03.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/etsug/etsug_timedata_examples03.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this block of code :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   do i=1 to _length_;
      oilshare[i] = oil[i] / roil[i];
      gasshare[i] = gas[i] / rgas[i];
   end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;, you can use [i] , but also [i+7] or [i-4].&lt;BR /&gt;The full time series (within the current by-group) is in-memory, so you jump back and forth in the time series.&lt;/P&gt;
&lt;P&gt;Also, you can make an expression which involves value[i-2] for one variable and value[i+2] for another variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2023 23:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/894189#M44301</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-09-13T23:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: calculate the average for a [+1,+3} and a [-3,-1] window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/894190#M44302</link>
      <description>Good to know.  Thx.</description>
      <pubDate>Wed, 13 Sep 2023 23:33:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/calculate-the-average-for-a-1-3-and-a-3-1-window/m-p/894190#M44302</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-13T23:33:51Z</dc:date>
    </item>
  </channel>
</rss>

