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?
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 lock in 2025 pricing—just $495!
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.