To resolve the week numbering issues for the 2025 season in the ip2 dataset, add the following code within the data step for ip2 under the "2025 adjustments" section. This will correct the week labels by adjusting wk1 , wk2 , year , and mth2 based on the specified conditions:
data ip2;
set ip;
format season_yr $20.;
/* Determine season year */
if '202009' <= month3 <= '202108' then season_yr = "Yr_20_21";
else if '202109' <= month3 <= '202208' then season_yr = "Yr_21_22";
else if '202209' <= month3 <= '202308' then season_yr = "Yr_22_23";
else if '202309' <= month3 <= '202408' then season_yr = "Yr_23_24";
else if '202409' <= month3 <= '202508' then season_yr = "Yr_24_25";
else season_yr = 'Other';
/* ... existing code ... */
/* 2025 Adjustments */
if season_yr = "Yr_24_25" then do;
/* Adjust weeks spanning into 2025 (wk53 from 2024 becomes 25_wk01) */
if wk1 in ("wk53", "wk00") then do;
wk1 = "wk01";
wk2 = "25_wk01";
year = "2025";
mth2 = "01"; /* Set to January */
end
/* Increment subsequent weeks by 1 (wk01 becomes 25_wk02) */
else if wk1 = "wk01" then do;
wk1 = "wk02";
wk2 = "25_wk02";
year = "2025";
mth2 = "01";
end;
end;
month = year || mth2;
run;
Explanation:
Condition on season_yr : Targets only the "Yr_24_25" season.
Handling wk53 and wk00 : Converts both to wk01 (2025) with wk2 set to "25_wk01".
Adjusting wk01 to wk02 : Ensures the following week is incremented correctly.
Updates year and mth2 : Ensures consistency with the new week assignments (January 2025).
This adjustment ensures weeks crossing into 2025 are labeled correctly, eliminating invalid week numbers (e.g., 24_wk53 , 25_wk00 ) and aligns with the desired output structure.
Alternative (Less Hardcoded) Approach:
To reduce hardcoding, you could:
Derive the target year from wbeg / wend dates instead of hardcoding 2025 .
Use date functions to calculate week numbers dynamically.
Example snippet:
/* 2025 Adjustments (Less Hardcoded) */
if season_yr = "Yr_24_25" then do;
/* Calculate target year based on the week's end date */
target_year = year(wend);
target_week = week(wend); /* SAS week function */
if wk1 in ("wk53", "wk00") then do;
wk1 = "wk01";
wk2 = catx("_", put(target_year, z2.), "wk01");
year = put(target_year, 4.);
mth2 = "01";
end
else if wk1 = "wk01" then do;
wk1 = "wk02";
wk2 = catx("_", put(target_year, z2.), "wk02");
year = put(target_year, 4.);
mth2 = "01";
end;
end;
This still assumes some structure (e.g., target_year is derived from wend ), but reduces reliance on fixed values like "2025" .
If the week numbering issue is specific to the 2024-2025 transition and not a recurring pattern, the original hardcoded solution is practical and valid. For future-proofing, consider a dynamic approach.
Hope this helps.
... View more