BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

Hello Experts,

 

I have a question : if my date is, for example, '15Jan2021:0:0:0'dt, and I would like to find the last friday before this date, there is some function in SAS ?

 

Thank you very much !

1 ACCEPTED SOLUTION

Accepted Solutions
JosvanderVelden
SAS Super FREQ

Please run the code below and see if that works for you.

data work.have;
   input mydate:datetime15.;
datalines;
15Jan2020:0:0:0
15Jan2021:0:0:0
15Jan2022:0:0:0
15Jan2023:0:0:0
19Oct2023:0:0:0
20Oct2023:0:0:0
21Oct2023:0:0:0
;
run;
   
data want;
   set have;
   thisweekFriday = intnx('week.6', datepart(mydate), 0);
   lastweekFriday = intnx('week.6', datepart(mydate), -1);
   format mydate datetime18. thisweekFriday lastweekFriday date9.;
run;

View solution in original post

4 REPLIES 4
JosvanderVelden
SAS Super FREQ

Please run the code below and see if that works for you.

data work.have;
   input mydate:datetime15.;
datalines;
15Jan2020:0:0:0
15Jan2021:0:0:0
15Jan2022:0:0:0
15Jan2023:0:0:0
19Oct2023:0:0:0
20Oct2023:0:0:0
21Oct2023:0:0:0
;
run;
   
data want;
   set have;
   thisweekFriday = intnx('week.6', datepart(mydate), 0);
   lastweekFriday = intnx('week.6', datepart(mydate), -1);
   format mydate datetime18. thisweekFriday lastweekFriday date9.;
run;
SASdevAnneMarie
Barite | Level 11
Thank you very much !
PaigeMiller
Diamond | Level 26

I am confused as the title and text do not agree. In one case you ask for last weekday, and in the other case you ask for last Friday. These are not the same. Which do you really want?

--
Paige Miller
SASdevAnneMarie
Barite | Level 11
Sorry, It is actually day (friday) of last week before the date.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 742 views
  • 0 likes
  • 3 in conversation