<?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: Excluding the the previous 4 financial years of the merger year in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Excluding-the-the-previous-4-financial-years-of-the-merger-year/m-p/371955#M275939</link>
    <description>&lt;P&gt;I think that the following does what you want to achieve:&lt;/P&gt;
&lt;PRE&gt;data have;
  input year id treatment;
  cards;
1994 1 0
1995 1 0
1996 1 0
1997 1 0
1998 1 1
1999 1 0
2000 1 1
2001 1 0
2002 1 0
1996 2 0
1997 2 0
1998 2 0
1999 2 0
2000 2 0
2001 2 0
2002 2 0
;
proc sort data=have;
  by id year;
run;

data want;
  do until (last.id);
    set have;
    by id;
    array drops(45) _temporary_;
    array nodrops(45) _temporary_;
    if first.id then do;
      counter=0;
      nocounter=0;
      call missing(of drops(*));
      call missing(of nodrops(*));
    end;
    if treatment eq 1 then do;
      nocounter+1;
      nodrops(nocounter)=year;
      do i=1 to 4;
        counter+1;
        drops(counter)=year-i;
      end;
    end;
  end;
  do until (last.id);
    set have;
    by id;
    if year in nodrops or year not in drops then output;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jun 2017 01:58:47 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-06-30T01:58:47Z</dc:date>
    <item>
      <title>Excluding the the previous 4 financial years of the merger year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excluding-the-the-previous-4-financial-years-of-the-merger-year/m-p/371941#M275938</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following dataset. Here, year indicates financial year, id indicates a specific firm, &amp;nbsp;and treatment=1 indicates the financial year the company got merged with another company. I want to remove the previous 4 years of each merger year. But If another merger year fall in the previous 4 years, I want to keep the merger year. In the following example, company 1 has 1 merger in 1998 as indicated by treatment=1, so I want to remove the data of id 1 from the year 1994 to 1997. Now the same company 1 had another merger in the year 2000, so I want to remove the year 1999, 1997, and 1996. I am keeping 1998 because it is a merger year. I have included my expected output file just below my dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is just a sample example. My original file has 30000 US companies and 45 financial years for each company. I will really appreciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;year id treatment&lt;BR /&gt;1994 1 0&lt;BR /&gt;1995 1 0&lt;BR /&gt;1996 1 0&lt;BR /&gt;1997 1 0&lt;BR /&gt;1998 1 1&lt;BR /&gt;1999 1 0&lt;BR /&gt;2000 1 1&lt;BR /&gt;2001 1 0&lt;BR /&gt;2002 1 0&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1996 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1997 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1998 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1999 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2000 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2001 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2002 2 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Expected result:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;year id treatment&lt;BR /&gt;1998 1 1&lt;BR /&gt;2000 1 1&lt;BR /&gt;2001 1 0&lt;BR /&gt;2002 1 0&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1996 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1997 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1998 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1999 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2000 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2001 2 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2002 2 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 00:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excluding-the-the-previous-4-financial-years-of-the-merger-year/m-p/371941#M275938</guid>
      <dc:creator>nazmul</dc:creator>
      <dc:date>2017-06-30T00:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding the the previous 4 financial years of the merger year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excluding-the-the-previous-4-financial-years-of-the-merger-year/m-p/371955#M275939</link>
      <description>&lt;P&gt;I think that the following does what you want to achieve:&lt;/P&gt;
&lt;PRE&gt;data have;
  input year id treatment;
  cards;
1994 1 0
1995 1 0
1996 1 0
1997 1 0
1998 1 1
1999 1 0
2000 1 1
2001 1 0
2002 1 0
1996 2 0
1997 2 0
1998 2 0
1999 2 0
2000 2 0
2001 2 0
2002 2 0
;
proc sort data=have;
  by id year;
run;

data want;
  do until (last.id);
    set have;
    by id;
    array drops(45) _temporary_;
    array nodrops(45) _temporary_;
    if first.id then do;
      counter=0;
      nocounter=0;
      call missing(of drops(*));
      call missing(of nodrops(*));
    end;
    if treatment eq 1 then do;
      nocounter+1;
      nodrops(nocounter)=year;
      do i=1 to 4;
        counter+1;
        drops(counter)=year-i;
      end;
    end;
  end;
  do until (last.id);
    set have;
    by id;
    if year in nodrops or year not in drops then output;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 01:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excluding-the-the-previous-4-financial-years-of-the-merger-year/m-p/371955#M275939</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-30T01:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding the the previous 4 financial years of the merger year</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excluding-the-the-previous-4-financial-years-of-the-merger-year/m-p/371973#M275940</link>
      <description>Thank you so much sir!!&lt;BR /&gt;It has perfectly solved my problem.</description>
      <pubDate>Fri, 30 Jun 2017 02:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excluding-the-the-previous-4-financial-years-of-the-merger-year/m-p/371973#M275940</guid>
      <dc:creator>nazmul</dc:creator>
      <dc:date>2017-06-30T02:50:17Z</dc:date>
    </item>
  </channel>
</rss>

