BookmarkSubscribeRSS Feed
nickspencer
Obsidian | Level 7

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

3 REPLIES 3
SASKiwi
PROC Star

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;
novinosrin
Tourmaline | Level 20

@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;
SASKiwi
PROC Star

@novinosrin - thanks for the feedback. Not sure where ideas like that come from, but I do like using Boolean expressions a lot Smiley Happy

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1617 views
  • 4 likes
  • 3 in conversation