<?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: Counting the number of Zero value then exclude the inactive day in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667939#M200118</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
informat ID $8. date date9.;
format date date9.;
input ID  date   value;
cards;
131712 01JAN1987	.
131712 02JAN1987	40
131712 05JAN1987	80
131712 06JAN1987	60
131712 07JAN1987	.
131712 27DEC2019	.
131712 30DEC2019	.
131712 31DEC2019	.
28829X 01JAN1987   121.32
28829X 02JAN1987   32.37
28829X 05JAN1987   115.19
28829X 27DEC2019	.
28829X 30DEC2019	.
28829X 31DEC2019	.
131713 01JAN1987	.
131714 01JAN1987	.
;;;;
run;

*count missing and not missing;
proc means data=have noprint nway;
class date;
var value;
output out=nMissing NMISS=NMISS;
run;

*convert to a percent;
data pctMissing;
set nMissing;
PCT_MISS = NMISS/_freq_;
run;

*get list of dates where percent missing is over 90%;
proc sql;
create table filteredData as
select * 
from have where date not in (select date from pctMissing where PCT_MISS &amp;gt; 0.5);

quit;

/*slightly more efficient way to do the means and pctMissing data set
*creates a view with a flag as 0/1 for missing which can then be used in proc means to calculate the percentage*/
data temp / view=temp;
set have;

if missing(value) then flag = 1; else flag=0;
run;

proc means data=temp noprint nway;
class date;
var flag;
output out=pctMissing mean=PCT_MISS;
run;

*get list of dates where percent missing is over 90%;
proc sql;
create table filteredData as
select * 
from have where date not in (select date from pctMissing where PCT_MISS &amp;gt; 0.5);

quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 Jul 2020 03:05:13 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-07-09T03:05:13Z</dc:date>
    <item>
      <title>Counting the number of Zero value then exclude the inactive day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667934#M200114</link>
      <description>&lt;P&gt;Hi SAS community,&lt;/P&gt;&lt;P&gt;Today I faced a problem when trying to exclude the non-trading days from my dataset.&lt;/P&gt;&lt;P&gt;My dataset is described as below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Type date R

131712	01JAN1987	.
131712	02JAN1987	40
131712	05JAN1987	80
131712	06JAN1987	60
131712	07JAN1987	.
.
.
131712  27DEC2019	.
131712  30DEC2019	.
131712  31DEC2019	.
.
.
28829X  01JAN1987   121.32
28829X  02JAN1987   32.37
28829X  05JAN1987   115.19
.
.
28829X  27DEC2019	.
28829X  30DEC2019	.
28829X  31DEC2019	.
.
.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The first column is the label of the companies (character type) (I have around 10,000 stocks sorted ascendingly), the second column is about the date (ddmmyyyy9.) (daily data from 1/1/1987 to 31/12/2019), and the third column is a numeric variable named "return index" (R)accordingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My concern here is that: a day on which more than 90% of stocks have zero returns is non-trading days, and then I need to exclude these non-trading days.&lt;/P&gt;&lt;P&gt;Many thanks in advance.&lt;/P&gt;&lt;DIV class="eJOY__extension_root_class"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Jul 2020 02:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667934#M200114</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2020-07-09T02:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of Zero value then exclude the inactive day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667935#M200115</link>
      <description>Can you show what you've tried so far?</description>
      <pubDate>Thu, 09 Jul 2020 02:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667935#M200115</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-09T02:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of Zero value then exclude the inactive day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667936#M200116</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
     if not missing(R);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jul 2020 02:42:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667936#M200116</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-09T02:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of Zero value then exclude the inactive day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667937#M200117</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, thank you for your reply,&lt;/P&gt;&lt;P&gt;I am not sure about how to code for this question, but from the idea, I postulate one possible solution for this concern is to create a new column (obs_per_day_0) and count through the column R (+1 when R =0). Then after that, we compare obs_per_day_0 with the total number of companies in my dataset. If the number in each day of the column obs_per_day_0 is higher than 90% of the total number, I will exclude this day from the sample.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks.&lt;/P&gt;&lt;DIV class="eJOY__extension_root_class"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Jul 2020 02:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667937#M200117</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2020-07-09T02:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of Zero value then exclude the inactive day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667939#M200118</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
informat ID $8. date date9.;
format date date9.;
input ID  date   value;
cards;
131712 01JAN1987	.
131712 02JAN1987	40
131712 05JAN1987	80
131712 06JAN1987	60
131712 07JAN1987	.
131712 27DEC2019	.
131712 30DEC2019	.
131712 31DEC2019	.
28829X 01JAN1987   121.32
28829X 02JAN1987   32.37
28829X 05JAN1987   115.19
28829X 27DEC2019	.
28829X 30DEC2019	.
28829X 31DEC2019	.
131713 01JAN1987	.
131714 01JAN1987	.
;;;;
run;

*count missing and not missing;
proc means data=have noprint nway;
class date;
var value;
output out=nMissing NMISS=NMISS;
run;

*convert to a percent;
data pctMissing;
set nMissing;
PCT_MISS = NMISS/_freq_;
run;

*get list of dates where percent missing is over 90%;
proc sql;
create table filteredData as
select * 
from have where date not in (select date from pctMissing where PCT_MISS &amp;gt; 0.5);

quit;

/*slightly more efficient way to do the means and pctMissing data set
*creates a view with a flag as 0/1 for missing which can then be used in proc means to calculate the percentage*/
data temp / view=temp;
set have;

if missing(value) then flag = 1; else flag=0;
run;

proc means data=temp noprint nway;
class date;
var flag;
output out=pctMissing mean=PCT_MISS;
run;

*get list of dates where percent missing is over 90%;
proc sql;
create table filteredData as
select * 
from have where date not in (select date from pctMissing where PCT_MISS &amp;gt; 0.5);

quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Jul 2020 03:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667939#M200118</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-09T03:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of Zero value then exclude the inactive day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667942#M200120</link>
      <description>&lt;DIV class="eJOY__extension_root_class"&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;, it works successfully to me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I learn quite a bit from your solution and your "more efficient" way to get there.&lt;/P&gt;&lt;/DIV&gt;&lt;DIV class="eJOY__extension_root_class"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="eJOY__extension_root_class"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Jul 2020 03:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-the-number-of-Zero-value-then-exclude-the-inactive-day/m-p/667942#M200120</guid>
      <dc:creator>Phil_NZ</dc:creator>
      <dc:date>2020-07-09T03:37:03Z</dc:date>
    </item>
  </channel>
</rss>

