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

How do I identify dates that fall in the last week of the month?

 

 

How do I identify dates that fall in the last week of the month?

DATA dates;
INPUT startdt :mmddyy10.;
FORMAT startdt mmddyy10.;
DATALINES;
12/01/2000
09/30/2012
06/01/2001
09/01/2001
09/30/2018
09/30/2018
04/30/2017
;
RUN;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

DATA dates;
INPUT startdt :mmddyy10.;
first=nwkdom(5,2,month(startdt),year(startdt));
in_last_week=(startdt>=first);
FORMAT first startdt mmddyy10.;
DATALINES;
12/01/2000
09/30/2012
06/01/2001
09/01/2001
09/30/2018
09/30/2018
04/30/2017
;
RUN;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Please let us know how you define "week". Does it start on Saturday, or Sunday, or Monday? Or do you mean last 7 days? Or do you mean something else?

 

Please be specific and detailed.

--
Paige Miller
Astounding
Opal | Level 21

If you mean the last 7 days of the month, here's a way:

 

data want;
   set have;
   if (intnx('month', startdt, 1) -7) <= startdt < intnx('month', startdt, 1);
run;
Reeza
Super User

Assuming last 7 days.

data want;
set dates;
in_last_7days = startdt >= intnx('month', startdt, 0, 'e') - 7;
run;
Ksharp
Super User

DATA dates;
INPUT startdt :mmddyy10.;
first=nwkdom(5,2,month(startdt),year(startdt));
in_last_week=(startdt>=first);
FORMAT first startdt mmddyy10.;
DATALINES;
12/01/2000
09/30/2012
06/01/2001
09/01/2001
09/30/2018
09/30/2018
04/30/2017
;
RUN;
PamG
Obsidian | Level 7

Thanks you so much @Ksharp Ksharp.  This is exactly what I was looking for.  To be able to identify the start date of the last week of the month.  I wasn't aware of the NWKDOM function.  Than you for bringing it to our attention!!!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 326 views
  • 3 likes
  • 5 in conversation