Last active
October 13, 2020 06:25
-
-
Save statgeek/82d9f2854edc01560e0f to your computer and use it in GitHub Desktop.
SAS - Rename variables with a common suffix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************** | |
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