DATA Step, Macro, Functions and more

Identifying Weekend date from a given date

Reply
Contributor
Posts: 27

Identifying Weekend date from a given date

Wondering if someone could help me with the following problem. I have a dataset that contains a column called create date. Using this field I would like to identify the weekend date for any given create date. Any thoughts on how this could be done?
N/A
Posts: 0

Re: Identifying Weekend date from a given date

the function INTNX() will provide the next date that satisfies the interval boundary you seek. There are lots of examples at the web page http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000990883.htm .

Whether you want next weekend (Friday/Saturday/Sunday), or last, you'll find an interval definition to suit.

PeterC
Contributor
Posts: 27

Re: Identifying Weekend date from a given date

Posted in reply to deleted_user
Peter,

The INTNX() worked beautifully! Thank you for your suggestion .

AJ
Contributor
Posts: 31

Re: Identifying Weekend date from a given date

Hi SAS09,
A simple do loop with WEEKDAY function can also solve you problem.

data dx;
input cretdt YYMMDD10.;
do i = 0 to 7 until(weekdaynum in(1,7)) ;
weekdaynum=weekday(cretdt + i);
weekend_date=cretdt+i;
end;
format cretdt weekend_date YYMMDD10.;
datalines;
2009-04-03
2009-04-09
2009-04-15
;
run;
proc print;run;
Super Contributor
Super Contributor
Posts: 3,174

Re: Identifying Weekend date from a given date

Posted in reply to SushilNayak
To Sushil: I recommend you consider reading up on the much simpler approach, using the INTNX function, where the desired result can be generated in one assignment statement, given any SAS date variable.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 4 replies
  • 3566 views
  • 2 likes
  • 4 in conversation