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.

Ready to join fellow brilliant minds for the SAS Hackathon?

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