<?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: set a 3-year moving window starting at a given date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/set-a-3-year-moving-window-starting-at-a-given-date/m-p/692813#M211132</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have rewritten my question, please have a look&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I am still lost. I don't understand. Your output data set is the same as the input data set except that rows 1 and 8 are removed. It also seems as if the term "3-year moving window" means something different to you than it does to me, but I don't know what you mean.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Oct 2020 10:52:29 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-10-20T10:52:29Z</dc:date>
    <item>
      <title>set a 3-year moving window starting at a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-a-3-year-moving-window-starting-at-a-given-date/m-p/692657#M211037</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to set a 3-year moving window starting at a given date by the following code,&lt;/P&gt;&lt;PRE&gt;data have;
	infile cards dsd  dlm=",";
	input
	ID $
	publn_date :YYMMDD10.
	earliest_publn_date :YYMMDD10.
	;
	format
   publn_date YYMMDDD10.
   earliest_publn_date YYMMDDD10.
   ;
	cards;
1,1993-09-05,1990-09-04&lt;BR /&gt;2,1993-09-04,1990-09-04&lt;BR /&gt;3,1993-09-03,1990-09-04&lt;BR /&gt;4,1992-09-05,1990-09-04&lt;BR /&gt;5,1992-09-04,1990-09-04&lt;BR /&gt;6,1992-09-03,1990-09-04&lt;BR /&gt;7,1990-09-04,1990-09-04&lt;BR /&gt;8,1990-09-03,1990-09-04
	;;;;
run;

proc sql;
	create table want as
	select distinct 
	*
	from have 
        WHERE publn_date &amp;lt;= intnx('year', earliest_publn_date,4) /*a 3-year moving window starting at the earliest publication date  */
	AND publn_date &amp;gt;= earliest_publn_date
	;
quit;&lt;/PRE&gt;&lt;P&gt;it meanings, for each observation,&lt;/P&gt;&lt;P&gt;if 1) 'publn_date' &amp;gt;= the&amp;nbsp;'earliest_publn_date' and&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;2)&amp;nbsp;'publn_date' &amp;lt;= 'earliest_publn_date' + 3-year,&lt;/P&gt;&lt;P&gt;then it should be remain.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By using the earliest_publn_date '1990-09-04' as an example,&lt;/P&gt;&lt;P&gt;1) the earliest 'publn_date' should be as same as&amp;nbsp;earliest_publn_date '1990-09-04',&lt;/P&gt;&lt;P&gt;2) the&amp;nbsp;latest&amp;nbsp;'publn_date'&amp;nbsp;should be '1993-09-04', it is the 3 years after '1990-09-04',&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Namely, I expect to get table want&lt;/P&gt;&lt;PRE&gt;2,1993-09-04,1990-09-04
3,1993-09-03,1990-09-04
4,1992-09-05,1990-09-04
5,1992-09-04,1990-09-04
6,1992-09-03,1990-09-04
7,1990-09-04,1990-09-04&lt;/PRE&gt;&lt;P&gt;I expect to exclude obs 8 because&amp;nbsp;publn_date 1990-09-03 is earlier than earliest_publn_date 1990-09-04.&lt;/P&gt;&lt;P&gt;I expect to exclude obs 1 because&amp;nbsp;publn_date&amp;nbsp;1993-09-04 is the 3 years after '1990-09-04', and&amp;nbsp;1993-09-05 is later than it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I failed by using my code, could you please give me some suggestions about this?&lt;/P&gt;&lt;P&gt;thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 18:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-a-3-year-moving-window-starting-at-a-given-date/m-p/692657#M211037</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2020-10-19T18:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: set a 3-year moving window starting at a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-a-3-year-moving-window-starting-at-a-given-date/m-p/692658#M211038</link>
      <description>&lt;P&gt;I have to say that I don't understand the description of the problem and how the desired output is generated. Can you go through this in a little more detail?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 18:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-a-3-year-moving-window-starting-at-a-given-date/m-p/692658#M211038</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-19T18:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: set a 3-year moving window starting at a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-a-3-year-moving-window-starting-at-a-given-date/m-p/692662#M211039</link>
      <description>&lt;P&gt;A query with GROUP BY and HAVING clauses will keep the earliest dates together and restrict by publication date.&lt;/P&gt;
&lt;PRE&gt;proc sql;
	create table want as
  select * 
  from have
  group by earliest_publn_date
  having publn_date between earliest_publn_date and intnx('year', min(earliest_publn_date), 3, 'S')
  order by id
	;
quit;&lt;/PRE&gt;
&lt;P&gt;If the data has other ids with an earliest date whose 3-year window overlaps a different ids publication date (in other words an id can be in more than one earliest publication date 3-year window) you may end up needing a self join.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 18:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-a-3-year-moving-window-starting-at-a-given-date/m-p/692662#M211039</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-10-19T18:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: set a 3-year moving window starting at a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-a-3-year-moving-window-starting-at-a-given-date/m-p/692669#M211041</link>
      <description>I have rewritten my question, please have a look</description>
      <pubDate>Mon, 19 Oct 2020 18:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-a-3-year-moving-window-starting-at-a-given-date/m-p/692669#M211041</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2020-10-19T18:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: set a 3-year moving window starting at a given date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/set-a-3-year-moving-window-starting-at-a-given-date/m-p/692813#M211132</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have rewritten my question, please have a look&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I am still lost. I don't understand. Your output data set is the same as the input data set except that rows 1 and 8 are removed. It also seems as if the term "3-year moving window" means something different to you than it does to me, but I don't know what you mean.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 10:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/set-a-3-year-moving-window-starting-at-a-given-date/m-p/692813#M211132</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-20T10:52:29Z</dc:date>
    </item>
  </channel>
</rss>

