My code:
proc contents data=have out=list(keep=name) noprint;
data list1; set list(keep=name); if name in ('ID','Name','Code','Country','Type','Form','Status','Entity'); keep name;
data list2; set list; if substr(name, length(name)-3) = 'YEAR' then output; keep name;
data l2; set list1 list2;
proc sql noprint; select name into :l2 separated by ' ' from l2; quit;
data want_YEAR(keep=&l2); set have;
proc sql noprint; select catx("=", name, substr(name, 1, length(name)-5)) into :rename_list separated by " "
from sashelp.vcolumn where libname='WORK' and memname='HAVE_YEAR' and upper(trim(name)) like '%_YEAR'; quit;
proc datasets library=work nodetails nolist; modify have_YEAR; rename &rename_list; run; quit;
data final; set have_YEAR;
I have ran this code by replacing YEAR with the years I want and repeat the code for as many years as I needed. Now I need to run it over quite a few number of years so I need to automate it. How can I do this?