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?
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: