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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.