if year = "2024" and wk1 = "wk53" then do;
wk1 = "wk01";
wk2 = "25_wk01";
year = "2025";
mth2 = "01";
end;
if year = "2025" and wk1 = "wk00" then do;
wk1 = "wk01";
wk2 = "25_wk01";
year = "2025";
mth2 = "01";
end;
if year = "2025" and wk1 = "wk01" then do;
wk1 = "wk02";
wk2 = "25_wk02";
year = "2025";
mth2 = "01";
end;
I get this after running the above:
How do I change the second row to be 25_wk01? Not sure what is wrong with the if then do statements if it produced this result after telling it exactly what to do.
data ip5;
input season_yr: $20.
wbeg: DATE8.
wend: DATE8.
wk1: $4.
wk2 $8.
year $4.
year3 $6.
month3 $6.
month33 $3.
mth2: $2.
mth3: $6.
datalines;
Yr_24_25,29DEC24,04JAN25,24_wk53,Wk53,2024,2025,202501,JAN
Yr_24_25,29DEC24,04JAN25,25_wk00,Wk00,2025,2025,202501,JAN
Yr_24_25,05JAN25,11JAN25,25_wk01,Wk01,2025,2025,202501,JAN
;
run;
Not sure if this is a complete fix, but it's an issue that stands out.
If your first IF THEN finds a match:
if year = "2024" and wk1 = "wk53" then do;
wk1 = "wk01";
wk2 = "25_wk01";
year = "2025";
mth2 = "01";
end;
the program doesn't stop. It keeps going through the remaining logic. So the observation that meets the first set of conditions will automatically meet the third set of conditions:
if year = "2025" and wk1 = "wk01" then do;
wk1 = "wk02";
wk2 = "25_wk02";
year = "2025";
mth2 = "01";
end;
If that's the issue, you will need to familiarize yourself with ELSE before an IF THEN.
Not sure if this is a complete fix, but it's an issue that stands out.
If your first IF THEN finds a match:
if year = "2024" and wk1 = "wk53" then do;
wk1 = "wk01";
wk2 = "25_wk01";
year = "2025";
mth2 = "01";
end;
the program doesn't stop. It keeps going through the remaining logic. So the observation that meets the first set of conditions will automatically meet the third set of conditions:
if year = "2025" and wk1 = "wk01" then do;
wk1 = "wk02";
wk2 = "25_wk02";
year = "2025";
mth2 = "01";
end;
If that's the issue, you will need to familiarize yourself with ELSE before an IF THEN.
Thank you. I did exactly what you did in those two if then do statements and got this result (*also did one other step beforehand to put wk00 into wk53 then pushed it to wk_01):
The frequencies look reasonable and the date ranges look fine but for some reason the second row is not showing as "25_wk01" but listed as "25_wk02". The first and third rows are good. I thought the "end" in the if then do stops it from looking further.
if year = "2025" and wk1 = "wk00" then do;
wk1 = "wk53";
wk2 = "24_wk53";
year = "2024";
mth2 = "12";
end;
if year = "2024" and wk1 = "wk53" then do;
wk1 = "wk01";
wk2 = "25_wk01";
year = "2025";
mth2 = "01";
end;
if year = "2025" and wk1 = "wk01" then do;
wk1 = "wk02";
wk2 = "25_wk02";
year = "2025";
mth2 = "01";
end;
Ok I did the following and it looks like it worked with an else if statement, thank you!!
if year = "2024" and wk1 = "wk53" then do;
wk1 = "wk01";
wk2 = "25_wk01";
year = "2025";
mth2 = "01";
end;
else
if year = "2025" and wk1 = "wk01" then do;
wk1 = "wk02";
wk2 = "25_wk02";
year = "2025";
mth2 = "01";
end;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.