BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Deesee
Calcite | Level 5

Deesee_0-1737395232052.png

 

 

 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:

 

Deesee_3-1737394887497.png

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

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.

Deesee
Calcite | Level 5

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):

Deesee_0-1737407697708.png

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;
Deesee
Calcite | Level 5

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 885 views
  • 0 likes
  • 2 in conversation