Desktop productivity for business analysts and programmers

Finding Tuesday date

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

Finding Tuesday date

Dear All,

 

Good morning ! I need to find tuesday date of the week dynamically. 

 

For instance today date is 23-05-2018, when I run my code the date should be assigned to  22-05-2018

 

Another instance if run the code next week i.e 28-05-2018 , the date value should be assigned to 29-05-2018..

 

Please help to provide advise. Thank you.


Accepted Solutions
Solution
a month ago
Super User
Posts: 23,293

Re: Finding Tuesday date

Posted in reply to dhruvakumar

INTNX(). 

Align it to the beginning of the week and then add 2. Check the docs for the details. 

 

Tuesday = intnx('week', today(), 0, 'b') + 2;

 


@dhruvakumar wrote:

Dear All,

 

Good morning ! I need to find tuesday date of the week dynamically. 

 

For instance today date is 23-05-2018, when I run my code the date should be assigned to  22-05-2018

 

Another instance if run the code next week i.e 28-05-2018 , the date value should be assigned to 29-05-2018..

 

Please help to provide advise. Thank you.


 

View solution in original post


All Replies
Solution
a month ago
Super User
Posts: 23,293

Re: Finding Tuesday date

Posted in reply to dhruvakumar

INTNX(). 

Align it to the beginning of the week and then add 2. Check the docs for the details. 

 

Tuesday = intnx('week', today(), 0, 'b') + 2;

 


@dhruvakumar wrote:

Dear All,

 

Good morning ! I need to find tuesday date of the week dynamically. 

 

For instance today date is 23-05-2018, when I run my code the date should be assigned to  22-05-2018

 

Another instance if run the code next week i.e 28-05-2018 , the date value should be assigned to 29-05-2018..

 

Please help to provide advise. Thank you.


 

Occasional Contributor
Posts: 7

Re: Finding Tuesday date

Dear Reeza,

Thank a lot.It working fine.
Esteemed Advisor
Posts: 5,481

Re: Finding Tuesday date

Posted in reply to dhruvakumar

This is reliably done with SAS date interval functions:

 

data test;
do date = '01may2018'd to '31may2018'd;
    tuesday = intnx("day", intnx("week", date, 0), 2);
    output;
    end;
format date tuesday yymmdd10.;
run;

proc print data=test noobs; run;

i.e. find the date of the beginning of the week (a Sunday) and then move forward two days.

 

PG
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 126 views
  • 2 likes
  • 3 in conversation