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

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