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
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;
Hi @AlexeyS,
Try this:
saturday=intnx('week', date, 1)-1;
Edit:
Or, slightly shorter:
saturday=date+7-weekday(date);
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.