Skip to content

Instantly share code, notes, and snippets.

@statgeek
Last active October 13, 2020 06:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statgeek/82d9f2854edc01560e0f to your computer and use it in GitHub Desktop.
Save statgeek/82d9f2854edc01560e0f to your computer and use it in GitHub Desktop.
SAS - Rename variables with a common suffix
/********************************************************************
Example : Rename variables based on suffix rather than prefix
********************************************************************/
data sample;
do i=10000 to 12000;
start_date=i;
middle_date=i+3;
end_date=i+5;
date_no_change=start_date;
output;
end;
format start_date end_date middle_date date9.;
run;
proc sql noprint;
select catx("=", name, catt('DT_', tranwrd(upper(name), '_DATE', ' ')))
into :rename_list
separated by " "
from sashelp.vcolumn
where libname='WORK'
and memname='SAMPLE'
and upper(trim(name)) like '%_DATE';
quit;
%put &rename_list;
proc datasets library=work nodetails nolist;
modify sample;
rename &rename_list;
run; quit;
proc print data=sample noobs;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment