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?
Don't keep data (years) in structure (variable names). Also see Maxim 19.
Transpose the year... variables to a long dataset and extract tze year number from _NAME_. Everything will then turn into a simple WHERE or BY.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.