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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.