I'm Tasked to automate SAS programs on a windows task scheduler.Please note I'm a very new SAS developer.I have been reading about changing dates in program automatically
There are dates on these few SAS program, which we change manually everyday and run it.
Here are the situation of dates in the program:
1. Date= Today's Date. But if it is a Friday,Include dates between today(friday) and Sunday.
Where Date_received=20180809(today)
Where Date_received between 20180810 and 20180812
2. Date=Previous Date. But if it is Monday, Change date to Friday Date.
Where Date_received=20180807
If the program run on Monday, then , Where Date_received=20180810
3.Date=Last Sunday through Saturday
If the program run on Monday(say August 13), then , Where Date_received >20180805 and Date_received <20180811
I have been reading about MACROS and SAS functions.
Please help me figure out , if it is better with Macros or date functions.
Also, if possible, point to articles to write ( or better help me write) the Macros for these date functions.
Hopefully it is the right forum im posting into..( Base SAS programming forum).
-Thanks
SHree
As long as you use actual date values you should have no need to involve macros for most things. And the macro language has no actual native date manipulation so you would be calling data step functions anyway.
The function today() should return the day a program runs.
You can test the data of the week with the WEEKDAY function with a date value. Weekday( today() ) returns 1 for Sunday, 2 for Monday … 7 for Saturday.
So:
If weekday(today()) = 2 then do;
<Monday code>
end;
else if weekday(today()) = 6 then do;
<Friday code>
end;
The function INTNX can be used to set a date based on an existing date and an interval.
otherdate = intnx('day', today(), 2) ; for example would set a value of 2 days from today for the SAS date value corresponding to 11Aug2018 when run on 09Aug2018.
Your code sort of implies that you may be entering values such as 20180809 manually. Those are NOT date values as far as SAS is concerned. A literal date value would be entered in SAS using '09AUG2018'd. If you are comparing the results of the TODAY() function to variables that look like 20180809 then some work will need to be done. You would have to tell us whether your dates are numeric or character and if they always appear as that OR if they actually are SAS date valued variables and have a YYMMDDN8. format applied.
As long as you use actual date values you should have no need to involve macros for most things. And the macro language has no actual native date manipulation so you would be calling data step functions anyway.
The function today() should return the day a program runs.
You can test the data of the week with the WEEKDAY function with a date value. Weekday( today() ) returns 1 for Sunday, 2 for Monday … 7 for Saturday.
So:
If weekday(today()) = 2 then do;
<Monday code>
end;
else if weekday(today()) = 6 then do;
<Friday code>
end;
The function INTNX can be used to set a date based on an existing date and an interval.
otherdate = intnx('day', today(), 2) ; for example would set a value of 2 days from today for the SAS date value corresponding to 11Aug2018 when run on 09Aug2018.
Your code sort of implies that you may be entering values such as 20180809 manually. Those are NOT date values as far as SAS is concerned. A literal date value would be entered in SAS using '09AUG2018'd. If you are comparing the results of the TODAY() function to variables that look like 20180809 then some work will need to be done. You would have to tell us whether your dates are numeric or character and if they always appear as that OR if they actually are SAS date valued variables and have a YYMMDDN8. format applied.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.