<?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: Deleting days with observations only up to 17:00 in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/456998#M14124</link>
    <description>&lt;P&gt;You might look at Hour(time) &amp;lt; 17 or hour(time) ge 17&amp;nbsp;instead of pulling the variable apart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also consider weeday(datepart(time)) to consider which day of the week to process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the TIME varial you show is a non-standard datetime format though the first thing is likely to ensure your time is actually a SAS datetime value.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Apr 2018 18:08:28 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-04-24T18:08:28Z</dc:date>
    <item>
      <title>Deleting days with observations only up to 17:00</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/456992#M14123</link>
      <description>&lt;P&gt;Dear sas community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a huge dataset containing forex tick data, which is organised as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;Time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bid&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ask .....&lt;/DIV&gt;&lt;DIV&gt;01.01.2015:17:12:12.445&amp;nbsp;&amp;nbsp; xxxxxxxxxx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xxxxxxxxx&lt;BR /&gt;01.01.2015:17:13:32.565&amp;nbsp;&amp;nbsp; xxxxxxxxxx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xxxxxxxxx&lt;BR /&gt;01.01.2015:17:13:40.685&amp;nbsp;&amp;nbsp; xxxxxxxxxx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xxxxxxxxx&lt;BR /&gt;01.01.2015:17:14:59.895&amp;nbsp;&amp;nbsp; xxxxxxxxxx&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xxxxxxxxx&lt;BR /&gt;01.01.2015:17:15:22.354 &amp;nbsp;&amp;nbsp; xxxxxxxxxx&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xxxxxxxxx&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;My Problem is that some days e.g Sundays only have observations from 17:00 until midnight and other days only have observations from 00:00 until 17:00. To be able to work with the data, these days have to be removed. I tried the folowing:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data forex;
set forex;
seconds_time  = floor(Time);
days = datepart(Time);
run;

* removing days with observations only past 17:00

data forex2;
  set forex;
  by days seconds_time;
  retain del_flag;
  if first.days and timepart(seconds_time) ge '17:00't then del_flag=1;
  else if first.days then del_flag=0;
  if del_flag=1 then delete;
  drop del_flag;
run;

* removing days with observations only before 17:00

data forex2;
  set forex2;
  by days seconds_time;
  retain del_flag;
  if last.days and timepart(seconds_time) le '17:00't then del_flag=1;
  else if last.days then del_flag=0;
  if del_flag=1 then delete;
  drop del_flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This does not seem to work, however.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Any help is greatly appreciated!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Kind regards!&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 24 Apr 2018 17:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/456992#M14123</guid>
      <dc:creator>NewSASuser2018</dc:creator>
      <dc:date>2018-04-24T17:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting days with observations only up to 17:00</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/456998#M14124</link>
      <description>&lt;P&gt;You might look at Hour(time) &amp;lt; 17 or hour(time) ge 17&amp;nbsp;instead of pulling the variable apart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also consider weeday(datepart(time)) to consider which day of the week to process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the TIME varial you show is a non-standard datetime format though the first thing is likely to ensure your time is actually a SAS datetime value.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 18:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/456998#M14124</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-24T18:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting days with observations only up to 17:00</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457005#M14125</link>
      <description>&lt;P&gt;Thanks for the quick response! sample data is now attached!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are no errors in the log. SaS does, however seem to flag random observations. So basically it does not flag a day where the last observation is at 16:59:30.3332 but might flag a day where the last observation is well past 17:00.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.S. this is my import statement:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import 
datafile=df01 out=forex DBMS=csv replace; 
delimiter=',';
run;quit;

data forex;
set forex;
format Time datetime24.3;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 18:21:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457005#M14125</guid>
      <dc:creator>NewSASuser2018</dc:creator>
      <dc:date>2018-04-24T18:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting days with observations only up to 17:00</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457011#M14126</link>
      <description>&lt;P&gt;Here's an approach that should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;For each observation, separate out DAY and TIME.&lt;/LI&gt;
&lt;LI&gt;Create a summary data set:&amp;nbsp; for each DAY, get the minimum and maximum TIME.&lt;/LI&gt;
&lt;LI&gt;Use your rules to determine whether that DAY should be kept or deleted.&lt;/LI&gt;
&lt;LI&gt;MERGE your summary data set back into the original data set, and apply your deletion decisions.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 24 Apr 2018 18:30:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457011#M14126</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-24T18:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting days with observations only up to 17:00</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457014#M14127</link>
      <description>This seems like a good idea! I am new to sas, however, or at least have very little experience and struggle with the syntax. Could you kindly provide a more detailed describtion?&lt;BR /&gt;</description>
      <pubDate>Tue, 24 Apr 2018 18:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457014#M14127</guid>
      <dc:creator>NewSASuser2018</dc:creator>
      <dc:date>2018-04-24T18:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting days with observations only up to 17:00</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457017#M14128</link>
      <description>Although your hint regarding me possibly having selected an unsuitable time format, if I apply the hour function as you suggested sas extracts the hours correctly.</description>
      <pubDate>Tue, 24 Apr 2018 18:40:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457017#M14128</guid>
      <dc:creator>NewSASuser2018</dc:creator>
      <dc:date>2018-04-24T18:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting days with observations only up to 17:00</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457018#M14129</link>
      <description>&lt;P&gt;It seems you have seen the DATEPART function.&amp;nbsp; If that's working properly, there is also TIMEPART:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;just_day = datepart(time);&lt;/P&gt;
&lt;P&gt;just_time = timepart(time);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Summarizing data is a must-learn topic:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=temp nway;&lt;/P&gt;
&lt;P&gt;class day;&lt;/P&gt;
&lt;P&gt;var time;&lt;/P&gt;
&lt;P&gt;output out=daily_stats (keep=day min_time max_time) min=min_time max=max_time;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will need to process this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data daily_stats2;&lt;/P&gt;
&lt;P&gt;set daily_stats;&lt;/P&gt;
&lt;P&gt;*** Examine MIN_TIME and MAX_TIME to set a deletion flag;&lt;/P&gt;
&lt;P&gt;keep day deletion_flag;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;merge daily_stats2 temp;&lt;/P&gt;
&lt;P&gt;by day;&lt;/P&gt;
&lt;P&gt;if deletion_flag=1 then delete;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's the idea of it, with most of the code in place.&amp;nbsp; You still need to examine the values in the MIN_TIME and MAX_TIME variables, and come up with logic that determines which days get deleted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last step assumes that your original data will be in order by date.&amp;nbsp; If that's not the case, you will need to sort it before merging.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 18:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457018#M14129</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-24T18:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting days with observations only up to 17:00</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457019#M14130</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
set have;
t=datepart(time);
t1=timepart(time);
format t date9. t1 time.;
run;

data want;
call missing(flag);
do until(last.t);
set temp;
by t t1;
if first.t and t1&amp;gt;='17:00't then flag=1;
else if last.t and t1&amp;lt;='17:00't  then flag=1;
end;
do until(last.t);
set temp;
by t t1;
if not flag  then output;
end;
drop t:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Apr 2018 18:45:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457019#M14130</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-24T18:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting days with observations only up to 17:00</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457027#M14131</link>
      <description>&lt;P&gt;More fun:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *
from have
group by datepart(time)
having not(min(timepart(time))&amp;gt;='17:00't) and  not(max(timepart(time))&amp;lt;='17:00't);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Apr 2018 19:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457027#M14131</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-24T19:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting days with observations only up to 17:00</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457076#M14133</link>
      <description>Thanks for all the great and very helpful answers! I appreciate it.</description>
      <pubDate>Tue, 24 Apr 2018 21:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Deleting-days-with-observations-only-up-to-17-00/m-p/457076#M14133</guid>
      <dc:creator>NewSASuser2018</dc:creator>
      <dc:date>2018-04-24T21:23:39Z</dc:date>
    </item>
  </channel>
</rss>

