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 !
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;
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;
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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.