Help using Base SAS procedures

dates recurring and so repeating the same'ish code

Reply
Contributor
Posts: 56

dates recurring and so repeating the same'ish code

I know this must be a basic question but its really bothering me as to how to do it. I have code,

proc expand data=work.gbpusd_5min out=work.gbpusd_5min_modified;
where date≤'04JUN2000:22:30'dt
or
date≥'06JUN2000:23:00'dt and date≤"11JUN2000:22:30"dt
or
date≥'13JUN2000:23:00'dt and date≤'18JUN2000:22:30'dt
or
date≥'20JUN2000:23:00'dt and date≤'25JUN2000:22:30'dt;
run;

but this is just the tip of the iceberg, that is I need to have more and more of these 'or date≥... and date≤.....' statements, like 1000's of them so I don't want to write it all out by hand but need some kind of loop/while/do syntax.

The datetimes are all 7 days after the preceding one on the line before, so I'm just looking to add seven days then spit the code out again.

But I'm stumped at how to do it. I'm basically trying to take out data between Friday night at 10.30pm until Sunday night at 11pm by just including the date between these datetimes. My time series is over 20 years of data.

Any help would be much appreciated.

Message was edited by: skipper Message was edited by: skipper
Regular Contributor
Posts: 241

Re: dates recurring and so repeating the same'ish code

Would this work?



   /* test data */


   data one;


      do datetime = '04jun2000:22:30'dt to '04jun2004:00:00'dt by 300;


         output;


      end;


      format datetime datetime.;


   run;


 


   /* remove any record between Fri 10:30pm and Sun 11:00pm, exclusive */


   data two;


      set one;


      select(weekday(datepart(datetime))); 


         when(6) if timepart(datetime) < '22:30't then output; /* fri */


         when(7) ;                               /* do nothing on sat */


         when(1) if '23:00't < timepart(datetime) then output; /* sun */


         otherwise output;


      end;


   run;

Contributor
Posts: 56

Re: dates recurring and so repeating the same'ish code

Posted in reply to chang_y_chung_hotmail_com
Thank you so much for your wisdom and excellent coding skills, it works perfectly.

Thanks
Super User
Posts: 11,343

Re: dates recurring and so repeating the same'ish code

Or for use in a where clause

Where not ((weekday(datepart(date))=6 and timepart(date) ge "23:00"t) or
weekday(datepart(date))=7 or
(weekday(datepart(date))=1 and timepart(date) le "23:30"t));
Ask a Question
Discussion stats
  • 3 replies
  • 127 views
  • 0 likes
  • 3 in conversation