Hi everyone,
Is there any Sas function that returns the current date and time if it is a weekday but returns the next weekday’s date and time if it is saturday or Sunday ?
Or do I need to write the conditional statement? If yes, any suggestions is appreciated.
Thanks in advance
How about this? No conditional code, but uses a Boolean expression instead.
data _null_;
format date_next date_now date9.;
date_now = '14jul2018'd;
date_next = intnx('WEEKDAY',date_now , (weekday(date_now) in (1,7)));
put _all_;
run;
Datetime version
data _null_;
format date_next date_now datetime24.;
date_now = '14jul2018:00:00:00'dt;
date_next = intnx('DTWEEKDAY', date_now , (weekday(datepart(date_now)) in (1,7)));
put _all_;
run;
@SASKiwi Super slick and elegant. Seems like an art to strike it big and at the right time to have that idea cross your mind in applying the right logic. Thank you for sharing.
I was trying a rather ugly way, lol->
data w;
format date_now new_Date date9. ;
do date_now = '10jun2018'd to '30jun2018'd;
new_Date= (weekday(date_now)=7)*date_now+(2*(weekday(date_now)=7))
+ (weekday(date_now)=1)*date_now+(1*(weekday(date_now)=1))+ (weekday(date_now) not in (1,7))*date_now ;
output;
end;
run;
proc print noobs;run;
@novinosrin - thanks for the feedback. Not sure where ideas like that come from, but I do like using Boolean expressions a lot ![]()
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.