turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Data Management
- /
- Forum
- /
- Determine the week number of a month

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-27-2017 12:46 PM

Hi guys

I have a variable called "_datadate" that include all Friday from May 2015 to May 2017, I want to output all Friday which is 3rd Friday in the month, I use this code "

DATA AAPL_TEsT1;

set AAPL_test;

week =intck('_datadate',intnx('month',date,0),date)+1;

run; "

But it not work.

I need some suggestions for this issue.

Thank you.

Accepted Solutions

Solution

10-27-2017
01:11 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Xinhui

10-27-2017 01:02 PM

Here's a different way to calculate WEEK:

week = ceil(day(_datadate)/7);

If you know that your data set contains only Fridays, you could easily follow that with:

if week = 3;

If your data set might contain some non-Fridays, you would have to add a condition:

if week = 3 and weekday(_datadate)=6;

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Xinhui

10-27-2017 12:55 PM

you need to calculate for weekday

https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201173.htm

if week = 3 and weekday = 6

will give your 3rd Friday of everymonth

Solution

10-27-2017
01:11 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Xinhui

10-27-2017 01:02 PM

Here's a different way to calculate WEEK:

week = ceil(day(_datadate)/7);

If you know that your data set contains only Fridays, you could easily follow that with:

if week = 3;

If your data set might contain some non-Fridays, you would have to add a condition:

if week = 3 and weekday(_datadate)=6;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Astounding

10-27-2017 01:10 PM

solve my problem！！！！ thank you very much!!!!!!!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Xinhui

10-27-2017 01:12 PM

NWKDOM() may be easier to work with.

Returns the date for the nth occurrence of a weekday for the specified month and year.