<?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: keep multiple rows based the conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/895533#M353831</link>
    <description>&lt;P&gt;Thank you both! I went back to rectify my mistake of the fiscal year, fiscal begin date, and fiscal end date. Below are my new codes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ciqt.company_matching9;
	set ciqt.company_matching9;
	fyrbegyear = year(fyrbegdt);
	fyrbegmonth = month(fyrbegdt);
	fyrbegday = day(fyrbegdt);
	fyrendyear = year(fyrenddt);
	fyrendmonth = month(fyrenddt);
	fyrendday = day(fyrenddt);
run;


data ciqt.company_matching10;
	set ciqt.company_matching9;
	if not missing(startyear) and not missing(startmonh) and not missing(startday) then do;
		if fyrbegyear&amp;gt;=startyear and fyrbegmonth&amp;gt;=startmonth and fyrbegday&amp;gt;=startday then output;
	end;
	else if not missing(startyear) and not missing(startmonh) and missing(startday) then do;
		if fyrbegyear&amp;gt;=startyear and fyrbegmonth&amp;gt;=startmonth then output;
	end;
	else if not missing(startyear) and missing(startmonh) then do;
		if fyrbegyear&amp;gt;=startyear then output;
	end;
	else if missing(startyear) then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think my logic is correct, but I do not know why, for example:&lt;/P&gt;
&lt;P&gt;an observation of fyrbegdt=01JAN2010, startyear=2010, startmonth=10, and missing startday is still kept in my dataset in the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know if I should provide a subset of my raw data. Thank you.&lt;/P&gt;</description>
    <pubDate>Sat, 23 Sep 2023 16:18:18 GMT</pubDate>
    <dc:creator>Jarvin99</dc:creator>
    <dc:date>2023-09-23T16:18:18Z</dc:date>
    <item>
      <title>keep multiple rows based the conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894682#M353409</link>
      <description>&lt;P&gt;Hi all, I am really new to SAS...I would like to know whether I can remove certain rows by restricting that gvkey_startdate &amp;lt;= fiscal_year &amp;lt;= gvkey_enddate. The raw database looks like this:&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="83"&gt;
&lt;P&gt;Person_id&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="89"&gt;
&lt;P&gt;Company_id&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="75"&gt;
&lt;P&gt;gvkey&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="115"&gt;
&lt;P&gt;Gvkey_startdate&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;Gvkey_enddate&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="69"&gt;
&lt;P&gt;Fiscal year&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="59"&gt;
&lt;P&gt;roa&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="83"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="89"&gt;
&lt;P&gt;Abcd&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="75"&gt;
&lt;P&gt;1234&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="115"&gt;
&lt;P&gt;27Nov1999&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;27Sep2010&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="69"&gt;
&lt;P&gt;2000&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="59"&gt;
&lt;P&gt;7.35&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="83"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="89"&gt;
&lt;P&gt;Abcd&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="75"&gt;
&lt;P&gt;8801&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="115"&gt;
&lt;P&gt;20Jan2011&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="69"&gt;
&lt;P&gt;2000&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="59"&gt;
&lt;P&gt;7.35&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="83"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="89"&gt;
&lt;P&gt;Abcd&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="75"&gt;
&lt;P&gt;1234&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="115"&gt;
&lt;P&gt;27Nov1999&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;27Sep2010&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="69"&gt;
&lt;P&gt;2012&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="59"&gt;
&lt;P&gt;6.42&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="83"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="89"&gt;
&lt;P&gt;Abcd&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="75"&gt;
&lt;P&gt;8801&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="115"&gt;
&lt;P&gt;20Jan2011&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="69"&gt;
&lt;P&gt;2012&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="59"&gt;
&lt;P&gt;6.42&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="83"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="89"&gt;
&lt;P&gt;Sdfg&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="75"&gt;
&lt;P&gt;2367&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="115"&gt;
&lt;P&gt;01Apr2000&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="69"&gt;
&lt;P&gt;2001&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="59"&gt;
&lt;P&gt;1.1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="83"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="89"&gt;
&lt;P&gt;Sdfg&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="75"&gt;
&lt;P&gt;2367&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="115"&gt;
&lt;P&gt;01Apr2000&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="69"&gt;
&lt;P&gt;2002&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="59"&gt;
&lt;P&gt;1.49&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="83"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="89"&gt;
&lt;P&gt;Cvbn&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="75"&gt;
&lt;P&gt;5678&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="115"&gt;
&lt;P&gt;01Sep1999&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;30Jun2005&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="69"&gt;
&lt;P&gt;2000&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="59"&gt;
&lt;P&gt;0.52&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="83"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="89"&gt;
&lt;P&gt;Cvbn&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="75"&gt;
&lt;P&gt;5678&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="115"&gt;
&lt;P&gt;01Sep1999&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;30Jun2005&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="69"&gt;
&lt;P&gt;2001&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="59"&gt;
&lt;P&gt;0.53&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="83"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="89"&gt;
&lt;P&gt;Cvbn&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="75"&gt;
&lt;P&gt;5678&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="115"&gt;
&lt;P&gt;01Sep1999&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="112"&gt;
&lt;P&gt;30Jun2005&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="69"&gt;
&lt;P&gt;2002&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="59"&gt;
&lt;P&gt;0.91&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The final product I want should be like this:&lt;/P&gt;
&lt;TABLE width="656px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="82.9271px"&gt;
&lt;P&gt;Person_id&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="98.9896px"&gt;
&lt;P&gt;Company_id&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="74.5px"&gt;
&lt;P&gt;gvkey&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="128.979px"&gt;
&lt;P&gt;Gvkey_startdate&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="120.99px"&gt;
&lt;P&gt;Gvkey_enddate&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="90.2917px"&gt;
&lt;P&gt;Fiscal_year&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58.6562px"&gt;
&lt;P&gt;roa&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.9271px"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="98.9896px"&gt;
&lt;P&gt;Abcd&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="74.5px"&gt;
&lt;P&gt;1234&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="128.979px"&gt;
&lt;P&gt;27Nov1999&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="120.99px"&gt;
&lt;P&gt;27Sep2010&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="90.2917px"&gt;
&lt;P&gt;2000&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58.6562px"&gt;
&lt;P&gt;7.35&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.9271px"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="98.9896px"&gt;
&lt;P&gt;abcd&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="74.5px"&gt;
&lt;P&gt;8801&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="128.979px"&gt;
&lt;P&gt;20Jan2011&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="120.99px"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="90.2917px"&gt;
&lt;P&gt;2012&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58.6562px"&gt;
&lt;P&gt;6.42&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.9271px"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="98.9896px"&gt;
&lt;P&gt;Sdfg&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="74.5px"&gt;
&lt;P&gt;2367&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="128.979px"&gt;
&lt;P&gt;01Apr2000&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="120.99px"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="90.2917px"&gt;
&lt;P&gt;2001&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58.6562px"&gt;
&lt;P&gt;1.1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.9271px"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="98.9896px"&gt;
&lt;P&gt;Sdfg&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="74.5px"&gt;
&lt;P&gt;2367&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="128.979px"&gt;
&lt;P&gt;01Apr2000&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="120.99px"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="90.2917px"&gt;
&lt;P&gt;2002&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58.6562px"&gt;
&lt;P&gt;1.49&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.9271px"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="98.9896px"&gt;
&lt;P&gt;Cvbn&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="74.5px"&gt;
&lt;P&gt;5678&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="128.979px"&gt;
&lt;P&gt;01Sep1999&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="120.99px"&gt;
&lt;P&gt;30Jun2005&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="90.2917px"&gt;
&lt;P&gt;2000&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58.6562px"&gt;
&lt;P&gt;0.52&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.9271px"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="98.9896px"&gt;
&lt;P&gt;Cvbn&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="74.5px"&gt;
&lt;P&gt;5678&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="128.979px"&gt;
&lt;P&gt;01Sep1999&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="120.99px"&gt;
&lt;P&gt;30Jun2005&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="90.2917px"&gt;
&lt;P&gt;2001&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58.6562px"&gt;
&lt;P&gt;0.53&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82.9271px"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="98.9896px"&gt;
&lt;P&gt;cvbn&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="74.5px"&gt;
&lt;P&gt;5678&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="128.979px"&gt;
&lt;P&gt;01Sep1999&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="120.99px"&gt;
&lt;P&gt;30Jun2005&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="90.2917px"&gt;
&lt;P&gt;2002&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="58.6562px"&gt;
&lt;P&gt;0.91&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It will definitely help me a lot if you have a solution if you can remove a row based on other columns. Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Sep 2023 13:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894682#M353409</guid>
      <dc:creator>Jarvin99</dc:creator>
      <dc:date>2023-09-17T13:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: keep multiple rows based the conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894686#M353412</link>
      <description>&lt;P&gt;What does it mean to test if a year is between two dates? Can you explain this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mean any part of the year is between the two dates? Or do you mean the entire year is between the two dates? Or do you mean Jan 1 of that year is between the two dates? Or do you mean something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How does the logic work when gvkey_enddate is missing? Explain that too.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Sep 2023 14:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894686#M353412</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-17T14:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: keep multiple rows based the conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894692#M353416</link>
      <description>&lt;P&gt;Do you mean any part of the year is between the two dates?&lt;/P&gt;
&lt;P&gt;Answer: yes. So any date of the fiscal_year 2000 should be between gvkey_startdate and gvkey_enddate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How does the logic work when gvkey_enddate is missing? Explain that too.&lt;/P&gt;
&lt;P&gt;Answer: if the gvkey_enddate is missing, treat it as not ending yet. The reason why there is this gvkey_startdate and gvkey_enddate is due to the M&amp;amp;A. Hence, a company_id named 'Abcd' was acquired by the gvkey=8801 on 20Jan2011 and continues to be acquired until now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope my reply clarifies! Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Sep 2023 17:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894692#M353416</guid>
      <dc:creator>Jarvin99</dc:creator>
      <dc:date>2023-09-17T17:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: keep multiple rows based the conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894693#M353417</link>
      <description>&lt;P&gt;Okay, I will assume your dates are actual numeric SAS date values, and that year is the 4 digit integer you show. Please let me know if those assumptions are correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */

data want;
    set have;
    if not missing(gvkey_enddate) then do;
        if year(gvkey_startdate)&amp;lt;=fiscal_year&amp;lt;=year(gvkey_enddate) then output;
    end;
    else do;
        if year(gvkey_startdate)&amp;lt;=fiscal_year then output;
    end;
run;
   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From now on, please provide data as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;) and not as Excel files and not as data copied and pasted from Excel and not in any other format.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Sep 2023 18:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894693#M353417</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-17T18:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: keep multiple rows based the conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894695#M353419</link>
      <description>&lt;P&gt;You are using GVKEY, as a company identifier, which means you are using Compustat data.&amp;nbsp; Because you also have a person id variable, I'm guessing you may be using Compustat's Execucomp database.&amp;nbsp; It looks like you have date ranges for a given executive being associated with a given company.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the above is to point out that &lt;EM&gt;&lt;STRONG&gt;fiscal year in Compustat is NOT the same as calendar year&lt;/STRONG&gt;&lt;/EM&gt;, and that may be important to your research.&amp;nbsp; The fiscal year Compustat assigns to a company annual report is based on what month its fiscal year ends (I believe this follows IRS conventions).&amp;nbsp; For instance, a fiscal year that ends anytime in January through May is assigned the preceding year value.&amp;nbsp; So, for example, if fiscal year ends on May 31, 2020, it will be identified as fiscal year 2019 (June 1, 2019 through May 31, 2020).&amp;nbsp; &amp;nbsp;The rule is basically whichever calendar year has the bulk of the months in a fiscal year, that calendar year will be used as the fiscal year identifier.&amp;nbsp; And ties, i.e. fiscal years ending in June, are assigned the latter year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Compustat used to have (I suppose it still does, but I don't have access currently) a variable FY or FYM, with values 1 through 12 identifying the last month of the company's fiscal year, so you could construct the actual calendar date ranges of a fiscal year using fiscal_year (FYEAR) and FY.&amp;nbsp; &amp;nbsp;Compustat has also added an actual calendar date (variable DATADATE) in the Comlpustat Fundamentals database for quarterly and annual statements, but perhaps that's not in Execucomp.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The upshot is if you had a person leave a company on, say Feb 1, 2020, but the company's FY 2019 was June 1, 2019 through May 31, 2020, your test as I understand it would wrongly assume the person left the company AFTER the fiscal year was over.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on the actual needs for your research, you may need to consider generating actual calendar dates for each GVKEY fiscal year, either the joining with tables containing DATADATE, or by finding and using FY to generate calendar date ranges.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Sep 2023 19:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894695#M353419</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-17T19:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: keep multiple rows based the conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894698#M353420</link>
      <description>&lt;P&gt;Thanks, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; . I also thought about fiscal years not aligning with calendar years, and how it is can be different from company to company. I leave it up to the original poster &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/415810"&gt;@Jarvin99&lt;/a&gt; to clarify this, as this issue regarding fiscal years is something that he has not&amp;nbsp; mentioned (and really should have been mentioned in the first post).&lt;/P&gt;</description>
      <pubDate>Sun, 17 Sep 2023 19:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/894698#M353420</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-17T19:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: keep multiple rows based the conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/895533#M353831</link>
      <description>&lt;P&gt;Thank you both! I went back to rectify my mistake of the fiscal year, fiscal begin date, and fiscal end date. Below are my new codes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ciqt.company_matching9;
	set ciqt.company_matching9;
	fyrbegyear = year(fyrbegdt);
	fyrbegmonth = month(fyrbegdt);
	fyrbegday = day(fyrbegdt);
	fyrendyear = year(fyrenddt);
	fyrendmonth = month(fyrenddt);
	fyrendday = day(fyrenddt);
run;


data ciqt.company_matching10;
	set ciqt.company_matching9;
	if not missing(startyear) and not missing(startmonh) and not missing(startday) then do;
		if fyrbegyear&amp;gt;=startyear and fyrbegmonth&amp;gt;=startmonth and fyrbegday&amp;gt;=startday then output;
	end;
	else if not missing(startyear) and not missing(startmonh) and missing(startday) then do;
		if fyrbegyear&amp;gt;=startyear and fyrbegmonth&amp;gt;=startmonth then output;
	end;
	else if not missing(startyear) and missing(startmonh) then do;
		if fyrbegyear&amp;gt;=startyear then output;
	end;
	else if missing(startyear) then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think my logic is correct, but I do not know why, for example:&lt;/P&gt;
&lt;P&gt;an observation of fyrbegdt=01JAN2010, startyear=2010, startmonth=10, and missing startday is still kept in my dataset in the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know if I should provide a subset of my raw data. Thank you.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2023 16:18:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/895533#M353831</guid>
      <dc:creator>Jarvin99</dc:creator>
      <dc:date>2023-09-23T16:18:18Z</dc:date>
    </item>
    <item>
      <title>Re: keep multiple rows based the conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/895535#M353832</link>
      <description>&lt;P&gt;If you have the fiscal year begin and end dates as dates then just use them in your comparisons.&amp;nbsp; No need to break them into components and rebuild a date out of it.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2023 16:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/895535#M353832</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-23T16:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: keep multiple rows based the conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/895537#M353833</link>
      <description>&lt;P&gt;Emmm...I need to do it because my startyear, startmonth, and startday can be missing. So in cases where my startmonth and startday are missing, I can only compare startyear with the year of the fiscal date. Same thing for the cases where startmonth and startyear are non-missing but the startday is missing.&lt;/P&gt;
&lt;P&gt;FYI, startyear, startmonth and startday are from an employee's start job date whose form can be yyyy-mm, yyyy, or yyyy-mm-dd, depending on the information available.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2023 17:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/895537#M353833</guid>
      <dc:creator>Jarvin99</dc:creator>
      <dc:date>2023-09-23T17:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: keep multiple rows based the conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/895577#M353844</link>
      <description>&lt;P&gt;Before looking at your data, look at your log.&amp;nbsp; If the code you posted is an accurate copy of your program, then this should appear in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Variable startmonh is uninitialized.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You mis-spelled startmonth at least once in your code, so the statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; else if not missing(startyear) and missing(startmonh) then do;
    if fyrbegyear&amp;gt;=startyear then output;
  end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so even if previous IF conditions are not met your sample observation would qualify for the last one.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Sep 2023 14:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/895577#M353844</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-09-24T14:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: keep multiple rows based the conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/895589#M353851</link>
      <description>&lt;P&gt;I don't think many companies change FY in the middle of a month, so for the START dates that are only missing the day of the month just assume the first of the month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And for the START dates that only include a year what is the logic you want to use?&amp;nbsp; Do you assume it is the same as the FY?&amp;nbsp; Do you want to assume that START was the first of the year?&amp;nbsp; The first of July?&amp;nbsp; The first of the month that company uses to start a new FY?&lt;/P&gt;</description>
      <pubDate>Sun, 24 Sep 2023 16:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-multiple-rows-based-the-conditions/m-p/895589#M353851</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-24T16:24:37Z</dc:date>
    </item>
  </channel>
</rss>

