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

Hi,

For each date, i want to find the saturday date on the same week. But if the date is Sunday then the function have to return the next Saturday.

I use the following code :

saturday = intnx('week.7', date, 1);

This works as long as it is not about the Saturday itself. In this case, it returns the next Saturday. Please help.

How the function should work :

datesaturday
12/01/202215/01/2022
15/01/202215/01/2022
16/01/202222/01/2022

 

Thank you,

Alexey

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input date ddmmyy10.;
format date ddmmyy10.;
datalines;
12/01/2022 
15/01/2022 
16/01/2022 
;

data want;
   set have;
   saturday = intnx('week', date, 0, 'e');
   format saturday ddmmyy10.;
run;

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @AlexeyS,

 

Try this:

saturday=intnx('week', date, 1)-1;

 

Edit:

Or, slightly shorter:

saturday=date+7-weekday(date);

 

PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input date ddmmyy10.;
format date ddmmyy10.;
datalines;
12/01/2022 
15/01/2022 
16/01/2022 
;

data want;
   set have;
   saturday = intnx('week', date, 0, 'e');
   format saturday ddmmyy10.;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 1610 views
  • 7 likes
  • 3 in conversation