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
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.