DATA Step, Macro, Functions and more

Setting up date macro by day of week

Reply
N/A
Posts: 1

Setting up date macro by day of week

I run a program every weekday that pulls new data from the past 24 hours. So, I want to go back 1 and 31 days Tues-Thurs and 3 and 33 days on Mon. How do I set this up? This is the current code:

%LET DATEC = (CURRENT DATE - 31 DAYS);
%LET STARTQT = (CURRENT DATE - 1 DAYS);

When I have run the program the past two Mondays, I have manually changed the 31 and 1 to 33 and 3.

Thanks for your help!
Super Contributor
Super Contributor
Posts: 3,174

Re: Setting up date macro by day of week

Look at using the INTNX function in your code.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

intnx function site:sas.com

using sas dates intnx site:sas.com
Regular Contributor
Posts: 171

Re: Setting up date macro by day of week

In addition to the intnx function, you could also use the weekday function. For example:

%let weekday=%sysfunc(weekday(%sysfunc(today())));

If you create the macro variable weekday as above, it will have a value of 2 every Monday. Conditional logic could then be used to determine which date variables to use.
SAS Employee
Posts: 58

Re: Setting up date macro by day of week

In general, there's a lot of good info on using SAS dates here:

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a002200738.htm
Ask a Question
Discussion stats
  • 3 replies
  • 177 views
  • 0 likes
  • 4 in conversation