<?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: Finding average over a period of two weeks in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Finding-average-over-a-period-of-two-weeks/m-p/707718#M26541</link>
    <description>&lt;OL&gt;
&lt;LI&gt;Does the 'week' start on the first day in your data set? The first day in September? The first Sunday in September?&lt;/LI&gt;
&lt;LI&gt;Can a week cross months, what happens to weeks that split the month?&lt;/LI&gt;
&lt;LI&gt;Is it a moving week or two week intervals entirely?&lt;/LI&gt;
&lt;LI&gt;Can you have duplicate entries for as single date? If so, how will those be handled?&lt;/LI&gt;
&lt;LI&gt;Can you have data missing for a date? If so, how will those be handled?&lt;/LI&gt;
&lt;LI&gt;Is it for a single ID or multiple IDs?&lt;BR /&gt;&lt;BR /&gt;You may want to expand your sample data to cover some of the questions above, if they apply. &lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/351308"&gt;@mitrakos&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to figure out how to find the average of a value based off a range of time, specifically two weeks. Sample data is below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input ID date :yymmdd10. value;
format date yymmdd10.;
datalines;
1 2020-04-01 110
1 2020-04-02 120
1 2020-04-03 130
1 2020-04-04 110
1 2020-04-05 110
1 2020-04-06 115
1 2020-04-07 120 
1 2020-04-08 140 
1 2020-04-09 130
1 2020-04-10 110
1 2020-04-11 120
1 2020-04-12 130
1 2020-04-13 120
1 2020-04-14 130
1 2020-04-15 140
1 2020-04-16 135
1 2020-04-17 135
1 2020-04-18 130
1 2020-04-19 150
1 2020-04-20 155
1 2020-04-21 140
1 2020-04-22 145
1 2020-04-23 150
1 2020-04-24 150
1 2020-04-25 155
1 2020-04-26 145
1 2020-04-27 150
1 2020-04-28 160
1 2020-04-29 165
1 2020-04-30 165
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The dataset I am actually working with includes many more observations, from September 2019 to July 2020, but this is just a subset. I would like to find the average of the 'value' variable across a timeframe of two weeks, so Bimonthly essentially. Any idea on how to perform this? Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;</description>
    <pubDate>Tue, 22 Dec 2020 17:01:31 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-12-22T17:01:31Z</dc:date>
    <item>
      <title>Finding average over a period of two weeks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-average-over-a-period-of-two-weeks/m-p/707714#M26539</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to figure out how to find the average of a value based off a range of time, specifically two weeks. Sample data is below&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input ID date :yymmdd10. value;
format date yymmdd10.;
datalines;
1 2020-04-01 110
1 2020-04-02 120
1 2020-04-03 130
1 2020-04-04 110
1 2020-04-05 110
1 2020-04-06 115
1 2020-04-07 120 
1 2020-04-08 140 
1 2020-04-09 130
1 2020-04-10 110
1 2020-04-11 120
1 2020-04-12 130
1 2020-04-13 120
1 2020-04-14 130
1 2020-04-15 140
1 2020-04-16 135
1 2020-04-17 135
1 2020-04-18 130
1 2020-04-19 150
1 2020-04-20 155
1 2020-04-21 140
1 2020-04-22 145
1 2020-04-23 150
1 2020-04-24 150
1 2020-04-25 155
1 2020-04-26 145
1 2020-04-27 150
1 2020-04-28 160
1 2020-04-29 165
1 2020-04-30 165
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The dataset I am actually working with includes many more observations, from September 2019 to July 2020, but this is just a subset. I would like to find the average of the 'value' variable across a timeframe of two weeks, so Bimonthly essentially. Any idea on how to perform this? Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 16:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-average-over-a-period-of-two-weeks/m-p/707714#M26539</guid>
      <dc:creator>mitrakos</dc:creator>
      <dc:date>2020-12-22T16:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Finding average over a period of two weeks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-average-over-a-period-of-two-weeks/m-p/707717#M26540</link>
      <description>&lt;P&gt;Create a new group variable, as FLOOR((date - startdate) / 14). That will give you a running count of bi-weeks.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 16:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-average-over-a-period-of-two-weeks/m-p/707717#M26540</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-22T16:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: Finding average over a period of two weeks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-average-over-a-period-of-two-weeks/m-p/707718#M26541</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Does the 'week' start on the first day in your data set? The first day in September? The first Sunday in September?&lt;/LI&gt;
&lt;LI&gt;Can a week cross months, what happens to weeks that split the month?&lt;/LI&gt;
&lt;LI&gt;Is it a moving week or two week intervals entirely?&lt;/LI&gt;
&lt;LI&gt;Can you have duplicate entries for as single date? If so, how will those be handled?&lt;/LI&gt;
&lt;LI&gt;Can you have data missing for a date? If so, how will those be handled?&lt;/LI&gt;
&lt;LI&gt;Is it for a single ID or multiple IDs?&lt;BR /&gt;&lt;BR /&gt;You may want to expand your sample data to cover some of the questions above, if they apply. &lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/351308"&gt;@mitrakos&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to figure out how to find the average of a value based off a range of time, specifically two weeks. Sample data is below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input ID date :yymmdd10. value;
format date yymmdd10.;
datalines;
1 2020-04-01 110
1 2020-04-02 120
1 2020-04-03 130
1 2020-04-04 110
1 2020-04-05 110
1 2020-04-06 115
1 2020-04-07 120 
1 2020-04-08 140 
1 2020-04-09 130
1 2020-04-10 110
1 2020-04-11 120
1 2020-04-12 130
1 2020-04-13 120
1 2020-04-14 130
1 2020-04-15 140
1 2020-04-16 135
1 2020-04-17 135
1 2020-04-18 130
1 2020-04-19 150
1 2020-04-20 155
1 2020-04-21 140
1 2020-04-22 145
1 2020-04-23 150
1 2020-04-24 150
1 2020-04-25 155
1 2020-04-26 145
1 2020-04-27 150
1 2020-04-28 160
1 2020-04-29 165
1 2020-04-30 165
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The dataset I am actually working with includes many more observations, from September 2019 to July 2020, but this is just a subset. I would like to find the average of the 'value' variable across a timeframe of two weeks, so Bimonthly essentially. Any idea on how to perform this? Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Tue, 22 Dec 2020 17:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-average-over-a-period-of-two-weeks/m-p/707718#M26541</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-12-22T17:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: Finding average over a period of two weeks</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Finding-average-over-a-period-of-two-weeks/m-p/707720#M26542</link>
      <description>&lt;P&gt;I'm glad you &lt;STRONG&gt;didn't&lt;/STRONG&gt; say "running" average.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I love the INTNX() function.&amp;nbsp; This function delivers a way to make two week time periods.&amp;nbsp; To &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;'s point I believe this starts on Sunday.&amp;nbsp; You should check for yourself, but the interval parameter can be tweaked to be Monday using something like "week2&lt;U&gt;&lt;STRONG&gt;.1&lt;/STRONG&gt;&lt;/U&gt;".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data intnx;
  set test;
  date_BO2WP=intnx("week2",date,0);
  label date_BO2WP = "Beginning of two week period";
  format date: yymmdd10.;
run;

PROC MEANS DATA=WORK.INTNX
	NOPRINT
	CHARTYPE
	NWAY 
  MEAN NONOBS 	;

	VAR value;
	CLASS date_BO2WP /	ORDER=UNFORMATTED ASCENDING;
	BY ID;

OUTPUT 	OUT=WORK.MEANSummaryStats (drop=_WAY_ _TYPE_)
	
		MEAN()=

	/ AUTONAME AUTOLABEL  WAYS INHERIT
	;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2020 17:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Finding-average-over-a-period-of-two-weeks/m-p/707720#M26542</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2020-12-22T17:09:31Z</dc:date>
    </item>
  </channel>
</rss>

