<?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: Drop non-trading days where more than 50% stocks have zero returns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Drop-non-trading-days-where-more-than-50-stocks-have-zero/m-p/465612#M118774</link>
    <description>Thank you very much, it works very well &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Tue, 29 May 2018 06:51:59 GMT</pubDate>
    <dc:creator>MAC1430</dc:creator>
    <dc:date>2018-05-29T06:51:59Z</dc:date>
    <item>
      <title>Drop non-trading days where more than 50% stocks have zero returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-non-trading-days-where-more-than-50-stocks-have-zero/m-p/465587#M118764</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I want to delete non-trading days where more than 50% stocks have zero returns. For example 60% of the total stocks (3 out of 5) have zero returns for 2010-01-07. Therefore, I want to delete&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;2010-01-07 from the sample. I have millions of observations, so I would appreciate an efficient&amp;nbsp;code.&amp;nbsp;&lt;/SPAN&gt;Please find the SAS data below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks a lot for your help.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheema&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input stock date : yymmdd10. ret ;
format date yymmdd10.;
cards;
1	2010-01-07	0
1	2010-01-26	-0.02544
1	2010-01-29	0.03384
2	2010-01-07	0
2	2010-01-26	-0.06219
2	2010-01-29	0.01989
3	2010-01-07	0.02
3	2010-01-26	-0.04
3	2010-01-29	0.023
4	2010-01-07	0
4	2010-01-26	-0.02
4	2010-01-29	0.012
5	2010-01-07	0.01
5	2010-01-26	0.02
5	2010-01-29	-0.012
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 May 2018 04:08:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-non-trading-days-where-more-than-50-stocks-have-zero/m-p/465587#M118764</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2018-05-29T04:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: Drop non-trading days where more than 50% stocks have zero returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-non-trading-days-where-more-than-50-stocks-have-zero/m-p/465588#M118765</link>
      <description>&lt;P&gt;Test this for efficiency:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table trading as
select *
from have
group by date
having 
    0.5 * count(distinct stock) &amp;gt;= 
    count(distinct case when ret = 0 then stock else . end)
order by stock, date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;having an index on date should help a lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 04:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-non-trading-days-where-more-than-50-stocks-have-zero/m-p/465588#M118765</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-05-29T04:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Drop non-trading days where more than 50% stocks have zero returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-non-trading-days-where-more-than-50-stocks-have-zero/m-p/465589#M118766</link>
      <description>&lt;P&gt;If a stock can only be mentioned once on a given day, then the query can be simpler:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table trading2 as
select *
from have
group by date
having 
    0.5 * count(*) &amp;gt;= sum(ret=0)
order by stock, date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 May 2018 04:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-non-trading-days-where-more-than-50-stocks-have-zero/m-p/465589#M118766</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-05-29T04:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Drop non-trading days where more than 50% stocks have zero returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Drop-non-trading-days-where-more-than-50-stocks-have-zero/m-p/465612#M118774</link>
      <description>Thank you very much, it works very well &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 29 May 2018 06:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Drop-non-trading-days-where-more-than-50-stocks-have-zero/m-p/465612#M118774</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2018-05-29T06:51:59Z</dc:date>
    </item>
  </channel>
</rss>

