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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.