BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ricardo_Neves
Obsidian | Level 7

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use 

 

first of current week

 

intnx('week', today(), 0, 'b');

 

subtract 2 for Friday. 

 

Last_friday = intnx('week', today(), 0, 'b') - 2;

View solution in original post

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Reeza
Super User

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. 

Ricardo_Neves
Obsidian | Level 7

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.

Reeza
Super User

Use 

 

first of current week

 

intnx('week', today(), 0, 'b');

 

subtract 2 for Friday. 

 

Last_friday = intnx('week', today(), 0, 'b') - 2;

Ricardo_Neves
Obsidian | Level 7
that'll do it yes, thanks
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Then simply:

data want;
  set have;
  where today() - 8 <= date <= today();
run;

Will get up to 8 days prior based on date.

Ricardo_Neves
Obsidian | Level 7

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.

Reeza
Super User

@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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 2359 views
  • 1 like
  • 3 in conversation