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
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.
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.