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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

4 REPLIES 4
kiranv_
Rhodochrosite | Level 12

 

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

Astounding
PROC Star

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;

Xinhui
Obsidian | Level 7

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

Reeza
Super User

NWKDOM() may be easier to work with.

 

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1735 views
  • 3 likes
  • 4 in conversation