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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.