BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alexgouv
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Welcome to the SAS Communities 🙂

 

data _null_;
    date='11jun2019'd;
    newdate=intnx('week.6',date,1);

    put date= mmddyy10. // newdate= mmddyy10.;
run;
alexgouv
Obsidian | Level 7

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.

Cynthia_sas
Diamond | Level 26

Hi:

You just need to test if the original date is a Friday. Like this:

 

calc_friday.png

Cynthia

PeterClemmensen
Tourmaline | Level 20

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;
Ksharp
Super User
data _null_;
    date='11jun2019'd;
    newdate=intnx('week.7',date,0,'e');

    put date= mmddyy10. // newdate= mmddyy10.;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 5 replies
  • 1369 views
  • 2 likes
  • 4 in conversation