Hi,
I'm trying to create a 8 day interval that starts on Friday in order to get the previous Friday date to then select data from a Table with dates that go from Friday to Friday independently of the day the process runs.
Im trying this code:
data test; sexta = intnx('day8.6', '05Jan2017'd, 0,'BEGIN'); format sexta weekdate.; run;
When I use the date specified is the current date, but if I use the diferent dates (like the ones in the code above) it gets completly diffent days ( in the exemple I get a Monday).
Any idea why this happens?
Use
first of current week
intnx('week', today(), 0, 'b');
subtract 2 for Friday.
Last_friday = intnx('week', today(), 0, 'b') - 2;
The function does not work the way you think it does. Refer to the manual. If you want one observation per day for each of the eight days then you need a loop from date-8 to date, and an output:
data test; do sexta='05Jan2017'd - 7 to '05jan2017'd; output; end; format sexta weekdate.; run;
That's a really uncommon calculation to the point I suspect it may not be correct.
Can you explain more what you're trying to do? And remember that dates are numbers so we can do subtraction to get dates of interest.
I trying to create a SAS DI studio job that will run every week, typically on a Friday. But there are things that might change the day the job will execute (like holidays for exemple). The job will get data from tables and is supposed to get the data from the previous Friday until the run day. So I was trying to use the INTNX function to get the previous friday no matter what day it runs, that is why I indicated a 8 day interval that starts on Friday.
Use
first of current week
intnx('week', today(), 0, 'b');
subtract 2 for Friday.
Last_friday = intnx('week', today(), 0, 'b') - 2;
Then simply:
data want; set have; where today() - 8 <= date <= today(); run;
Will get up to 8 days prior based on date.
I thought about that, but I don't need 8 days, I need exactly Friday.
Reeza's response will do it, because using 'week' as the interval I seem to always get sunday.
@Ricardo_Neves wrote:
I thought about that, but I don't need 8 days, I need exactly Friday.
Reeza's response will do it, because using 'week' as the interval I seem to always get sunday.
This is more due to using a 0 and the alignment parameter of 'b' to align at the beginning of the week which is Sumday.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.