BookmarkSubscribeRSS Feed
SAS09
Calcite | Level 5
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?
4 REPLIES 4
deleted_user
Not applicable
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
SAS09
Calcite | Level 5
Peter,

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

AJ
SushilNayak
Obsidian | Level 7
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;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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