BookmarkSubscribeRSS Feed
skipper
Calcite | Level 5
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
3 REPLIES 3
chang_y_chung_hotmail_com
Obsidian | Level 7
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;

skipper
Calcite | Level 5
Thank you so much for your wisdom and excellent coding skills, it works perfectly.

Thanks
ballardw
Super User
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));

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 793 views
  • 0 likes
  • 3 in conversation