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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 813 views
  • 7 likes
  • 3 in conversation