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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.