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;
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.