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

I have a date variable and I want to be able to calculate its corresponding week start date. Example:

 

Have:

 

Date

1/5/2020

1/6/2020

1/7/2020

1/12/2020

1/21/2020

1/23/2020

 

Want:

Date:              Week Start Date: 

1/5/2020         1/5/2020

1/6/2020         1/5/2020

1/7/2020         1/5/2020

1/13/2020       1/12/2020

1/21/2020       1/19/2020

1/23/2020        1/19/2020

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20



data have;
input date :mmddyy10.;
format date mmddyy10.;
cards;
1/5/2020

1/6/2020

1/7/2020

1/12/2020

1/21/2020

1/23/2020
;

data Want;
 set have;
 Week_start=intnx('Week',date,0,'b');
 format Week_start mmddyy10.;
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20



data have;
input date :mmddyy10.;
format date mmddyy10.;
cards;
1/5/2020

1/6/2020

1/7/2020

1/12/2020

1/21/2020

1/23/2020
;

data Want;
 set have;
 Week_start=intnx('Week',date,0,'b');
 format Week_start mmddyy10.;
run;
Barkat
Pyrite | Level 9
Here the week_start starts on Sunday. How can I modify the code, so the week_start starts on Saturday?
Barkat
Pyrite | Level 9
I found that.

data Want;
set have;
Week_start=intnx('Week.7',date,0,'b');
format Week_start 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
  • 3 replies
  • 7940 views
  • 1 like
  • 3 in conversation