Hi,
I am trying to change a date to the Friday of that week. For example, if the date is 6/11/2019, I want the new one to be 6/14/2019. It can be created as a new variable or overwrite the old one it does not matter. If it helps, the old date variable is in the MMDDYY10. format.
No problem 🙂
data _null_;
date='11jun2019'd;
if weekday(date)=6 then newdate=date;
else newdate=intnx('week.6',date,1);
put date= mmddyy10. // newdate= mmddyy10.;
run;
Welcome to the SAS Communities 🙂
data _null_;
date='11jun2019'd;
newdate=intnx('week.6',date,1);
put date= mmddyy10. // newdate= mmddyy10.;
run;
draycut,
Thanks for the quick reply! I should have specified, but if the date is already a Friday I just want it to stay that date. The code you posted is causing Fridays to be displayed with the date of the following Friday.
Hi:
You just need to test if the original date is a Friday. Like this:
Cynthia
No problem 🙂
data _null_;
date='11jun2019'd;
if weekday(date)=6 then newdate=date;
else newdate=intnx('week.6',date,1);
put date= mmddyy10. // newdate= mmddyy10.;
run;
data _null_;
date='11jun2019'd;
newdate=intnx('week.7',date,0,'e');
put date= mmddyy10. // newdate= mmddyy10.;
run;
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.