<?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: Removing firms with small market cap in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652224#M195791</link>
    <description>&lt;P&gt;So when we look on the example data for GVKEY =&amp;nbsp;272762,&amp;nbsp; you want to delete daily data for 2005(09DEC05 mktcap=1.62) and 2006(29DEC06 mktcap=1.8) but keep daily data for 2007(18DEC07 mktcap=28.45) and 2008(05DEC08 mktcap=11.38), right?&lt;/P&gt;
&lt;P&gt;In that case the sql query should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
   select * from RET1
    where mktcap&amp;gt;5
  group by year, GVKEY
  order by gvkey, year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Btw. check code for `WANT_DAILY_v2` it should already do what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jun 2020 12:10:00 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2020-06-01T12:10:00Z</dc:date>
    <item>
      <title>Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652154#M195770</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;The dataset I am using has daily data for about 500 firms each year over a period of 15 years. I want to remove firms with a market capitalization (MKTCAP) of less than $5 million. To do this, I computed MKTCAP for each firm at the end of each year. Firms with MKTCAP &amp;lt; 5 are removed each year.&lt;/P&gt;&lt;P&gt;PART 1 of the code attached below, subsets the daily data to obtain only year-end observations.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data RET1;
	set RET;
	by year gvkey date;
	if last.gvkey;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;GVKEY refers to the firm's code and RET is the dataset with daily data. YEAR is the year variable created in SAS.&lt;/P&gt;&lt;P&gt;I then used PROC SQL to retain firms with MKTCAP&amp;gt;5 as follows:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
   select * from RET1
    where mktcap&amp;gt;5
  group by year
  order by gvkey, year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;While this did the trick of keeping only those firms with MKTCAP&amp;gt;5, I am however left with a dataset by GVKEY and YEAR.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure how to merge WANT (with yearly obs) with the original dataset RET (with daily obs) to obtain the daily dataset with only MKTCAP&amp;gt;5&lt;/P&gt;&lt;P&gt;Would appreciate your help and advice please. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 07:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652154#M195770</guid>
      <dc:creator>sjm</dc:creator>
      <dc:date>2020-06-01T07:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652159#M195773</link>
      <description>&lt;P&gt;Could you share some test data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 07:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652159#M195773</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-06-01T07:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652162#M195774</link>
      <description>&lt;P&gt;Dear Yabwon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attached is the test data RET for three firms, one of which, has the first few years where MKTCAP&amp;lt;5. The other two firms are large MKTCAP firms where MKTCAP&amp;gt;5 for all years.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 08:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652162#M195774</guid>
      <dc:creator>sjm</dc:creator>
      <dc:date>2020-06-01T08:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652166#M195775</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do I understand correct that you want to get something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT_DAILY as
   select RET.* from RET
    join
   WANT
   on RET.gvkey= WANT.gvkey 
    and RET.year = WANT.year
    order by year gvkey date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or am I missing something?&lt;/P&gt;
&lt;P&gt;If I'm right, alternative approach could be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT_DAILY_v2;

  do _N_=1 by 1 until(last.gvkey);  
	 set RET;
	 by year gvkey date;
	 if last.gvkey then 
    do;
      trigger = (mktcap&amp;gt;5);
    end;
  end;

  do _N_=1 to _N_;  
	 set RET;
	 if trigger then output;
  end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 09:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652166#M195775</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-06-01T09:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652176#M195776</link>
      <description>Dear Bart,&lt;BR /&gt;I tried the two suggested codes on the full dataset but the final dataset  (WANT_DAILY) still has firms with a mktcap of less than $5m.  &lt;BR /&gt;</description>
      <pubDate>Mon, 01 Jun 2020 09:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652176#M195776</guid>
      <dc:creator>sjm</dc:creator>
      <dc:date>2020-06-01T09:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652179#M195777</link>
      <description>&lt;P&gt;So you want to remove given company if it has at leas one case with&amp;nbsp;&lt;SPAN&gt;mktcap&amp;lt;5 ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Bart&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 10:04:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652179#M195777</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-06-01T10:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652198#M195787</link>
      <description>&lt;P&gt;Sorry, my message is probably not clear. Let me clarify.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have around daily data on about 500 firms over a period of 15 years. What I need to is to form a final dataset where the firms included each year have a market cap greater than $5m.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's say that there are 500 firms in 2015 and applying a simple rule, I find that 50 of them have a mktcap that is less than $5m.&amp;nbsp; This means that, for 2015, the dataset would have daily data on only the 400 firms with a mktcap greater than $5m.&amp;nbsp; The simple selection rule is to base the mktcap of the firm on its year-end value (last value of the year) and only select those with mktcap&amp;gt;$5m.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By that token, a firm excluded in the earlier years when its mktcap &amp;lt; $5m, may be included in later years when its mktcap exceeds $5m.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, the final dataset should only contain daily data on all firms with mktcap greater than $5m.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this is clearer. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 11:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652198#M195787</guid>
      <dc:creator>sjm</dc:creator>
      <dc:date>2020-06-01T11:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652199#M195788</link>
      <description>One minor correction to the message above:  For the second sentence of the second para, the figure should be 450 firms not 400 firms.</description>
      <pubDate>Mon, 01 Jun 2020 11:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652199#M195788</guid>
      <dc:creator>sjm</dc:creator>
      <dc:date>2020-06-01T11:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652224#M195791</link>
      <description>&lt;P&gt;So when we look on the example data for GVKEY =&amp;nbsp;272762,&amp;nbsp; you want to delete daily data for 2005(09DEC05 mktcap=1.62) and 2006(29DEC06 mktcap=1.8) but keep daily data for 2007(18DEC07 mktcap=28.45) and 2008(05DEC08 mktcap=11.38), right?&lt;/P&gt;
&lt;P&gt;In that case the sql query should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
   select * from RET1
    where mktcap&amp;gt;5
  group by year, GVKEY
  order by gvkey, year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Btw. check code for `WANT_DAILY_v2` it should already do what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 12:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652224#M195791</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-06-01T12:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652419#M195864</link>
      <description>&lt;P&gt;You have DAILY data, but want to exclude a firm for the entire year if the end-of-year market cap is &amp;lt;5, yes? &amp;nbsp; If you have daily data, then you have about 200 records (i.e.for trading dates) for each firm-year, with corresponding daily MKTCAP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your daily data is sorted by YEAR GVKEY DATE.&amp;nbsp; So you need to get to the last record of each year for each gvkey, check it's market cap value, then re-read the same daily data, either outputting or not the roughly 200 daily records for that firm/year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=keep_dummy);
  do until (last.gvkey=1);
    set ret ;
    by year gvkey date;
  end;
  keep_dummy=(mktcap&amp;gt;5);
  do until (last.gvkey);
    set ret;&lt;BR /&gt;    by year gvkey date;
    if keep_dummy=1 then output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if a gvkey only has, say, the first 9 months of data for a given year, then the mktcap criterion will depend on the end-of-September status, not end-of-December.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 03:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652419#M195864</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-06-02T03:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652434#M195874</link>
      <description>&lt;P&gt;I probably misunderstood something, but isn't this what you want?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data RET1;
	set RET;
	by year gvkey date;
	if last.gvkey and MKTCAP &amp;gt; 5;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 05:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/652434#M195874</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-02T05:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/658347#M197311</link>
      <description>Sorry for the late reply. The solution works! Thanks.</description>
      <pubDate>Sun, 14 Jun 2020 12:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/658347#M197311</guid>
      <dc:creator>sjm</dc:creator>
      <dc:date>2020-06-14T12:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Removing firms with small market cap</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/658348#M197312</link>
      <description>Sorry for the late reply. Thanks.</description>
      <pubDate>Sun, 14 Jun 2020 12:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-firms-with-small-market-cap/m-p/658348#M197312</guid>
      <dc:creator>sjm</dc:creator>
      <dc:date>2020-06-14T12:17:19Z</dc:date>
    </item>
  </channel>
</rss>

