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
SAS Super FREQ

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 676 views
  • 2 likes
  • 4 in conversation