data want;
set have;
retain begin;
if _n_ = 1 then begin = date;
week = intck('week`,begin,date) + 1;
drop begin;
run;
data want;
date = "04dec2023"d;
do week = 1 to 6;
output;
date + 7;
end;
format date ddmmyys10.;
run;
T
Date. Week
04/12/2023. 1
04/12/2023 1
11/12/2023. 2
18/12/2023.3
04/12/2023. 1
25/12/2023. 4
25/12/2023. 4
01/01/2024. 5
08/01/2024. 6
25/12/2023. 4
Does that mean you already have the dates in a dataset, and want to calculate the week numbers based on the earliest found date?
Yes, but week will be 1 for earliest date.
data want;
set have;
retain begin;
if _n_ = 1 then begin = date;
week = intck('week`,begin,date) + 1;
drop begin;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.