SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sophia_SAS
Obsidian | Level 7

Dear SAS Community,

I have a list of "Old_dates" of which I would like to create a new variable "New_dates" that groups the "Old_dates by week according to the last Saturday in that week.  See my example below.  As I have many years worth of dates, how do I automate the process?  I'd like to avoid manual coding for the new variable (i.e. if '02Mar2013' < old_date <=09Mar2013 then new_dates = '09Mar2013').

Note, old_dates may not always have all 7 days in a week listed.  Sometimes only 3-4 dates are listed per each 7 day time frame and one may or may not be a Saturday (see "New-dates=09Mar2013).

Thank you in advance!

Sophia

Old_dates     New_dates

24Feb2013 = 02Mar2013

25Feb2013 = 02Mar2013

26Feb2013 = 02Mar2013

27Feb2013 = 02Mar2013

28Feb2013 = 02Mar2013

01Mar2013 = 02Mar2013

02Mar2013 = 02Mar2013

05Mar2013 = 09Mar2013

06Mar2013 = 09Mar2013

07Mar2013 = 09Mar2013

08Mar2013 = 09Mar2013

11Mar2013 = 16Mar2013

12Mar2013 = 16Mar2013

13Mar2013 = 16Mar2013

16Mar2013 = 16Mar2013

1 ACCEPTED SOLUTION

Accepted Solutions
Keith
Obsidian | Level 7

new_dates=intnx('week',old_dates,0,'end');

View solution in original post

1 REPLY 1
Keith
Obsidian | Level 7

new_dates=intnx('week',old_dates,0,'end');

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1 reply
  • 1045 views
  • 1 like
  • 2 in conversation