First match the two lists.
proc transpose data=table1 (obs=0) out=old_names name=old_name ;
var _all_;
run;
proc transpose data=table2 out=new_names ;
var _all_;
run;
data names ;
set old_names;
set new_names;
run;
Once you have them matched up then use them to generate a RENAME statement.
filename code temp;
data _null_:
set names end=eof;
file code;
if _n_=1 then put 'rename' ;
length pair $200;
pair = catx('=',nliteral(old_name),nliteral(col1));
put @3 pair ;
if eof then put ';';
run;
Once you have the RENAME statement you can use it to rename the variables.
If the dataset is small just make a new dataset.
data want;
set table1;
%include code / source2;
run;
If the dataset is large you might want to use PROC DATASETS to modify the names in place.
proc datasets nolist lib=WORK ;
modify TABLE1 ;
%include code / source2;
run;
quit;
Note that the first step of matching the old name to the new name would be easier if the variables in TABLE2 had the same names as the corresponding variables in TABLE1.
proc transpose data=table2 out=names name=old_name;
var _all_ ;
run;
... View more