🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 01-13-2022 06:00 AM
(1517 views)
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 :
date | saturday |
12/01/2022 | 15/01/2022 |
15/01/2022 | 15/01/2022 |
16/01/2022 | 22/01/2022 |
Thank you,
Alexey
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @AlexeyS,
Try this:
saturday=intnx('week', date, 1)-1;
Edit:
Or, slightly shorter:
saturday=date+7-weekday(date);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;