Do Loop to output new column SAS

44 Views Asked by At

I have dataset that looks like this:

ID      Date        Calendar_Yr 
1     07/04/2023      2023          
1     09/01/2023      2023
1     02/01/2024      2024
1     04/04/2024      2024

I would like to have a dataset that looks like this:

ID      Date           Calendar_Yr   
1     07/04/2023       CY 2023    
1     09/01/2023       CY 2023   
1     02/01/2024       CY 2024
1     04/04/2024       CY 2024

Can put the column CY_Year into a macro variable and then try a do loop around a "if/then Column Name = "CY &CY_Year."

1

There are 1 best solutions below

0
Tom On

There is no need for looping to create your new variable.

data want;
   set have;
   length CY_Year $7 ;
   CY_Year = catx(' ','YR',Calendar_Yr);
run;

In general you use macro code to generate code, but there is no code generation needed for this problem.