/***************************************************************************************************************** SAS file name: alter_datasets File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate how to dymanically change attributes of SAS datasets Author: Peter Clemmensen Creation Date: 27/05/2019 This program supports the example page "" on SASnrd.com *****************************************************************************************************************/ /* Apply date9 format to all date variables */ data test1; input date1-date3 var1-var3; datalines; 1 1 1 1 2 3 ; proc datasets lib=work nolist; modify test1; format date: date9.; run;quit; proc contents data=test1; run; /* Change variable names for variables with 2018 in the name in test2 data set */ data test2; input one2018 $ two2018 $ three2018 $ var1-var3; datalines; a b c 1 2 3 ; data _null_; set sashelp.vcolumn end=lr; where libname='WORK' and memname='TEST2'; if _n_ = 1 then call execute('proc datasets lib=work nolist; modify test2;'); if find(name, '2018') ne 0 then call execute(compbl(cat('rename ', name, '=', tranwrd(name, '2018', '2019'), ';'))); if lr then call execute('quit;'); run; proc contents data=test2; run; /* Change data set names for all data sets with 2018 in the data set name */ data one; a=1;run; data two; b=1;run; data three; c=1;run; data one2018; d=1;run; data two2018; e=1;run; data three2018;f=1;run; data _null_; set sashelp.vcolumn end=lr; where libname='WORK' and find(memname, '2018') ne 0; if _n_ = 1 then call execute('proc datasets lib=work nolist;'); call execute(compbl(cat('change ', memname, '=', tranwrd(memname, '2018', '2019'), ';'))); if lr then call execute('quit;'); run;