Dear all,
I am importing several datasets into SAS which need to be harmonised following specific naming conventions. As such I need to rename the variables of diferente datasets from A to A', B to B', C to C', etc...
As the rename function implies that I have to edit every single import, I prefer to use a centralised dataset which contains the mapping between A and A', B and B', C and C', etc...
My problem is how can I link the imported table to the mapping tablel, producing the final renamed field table.
Thank you very much for your help.
Kind regards,
Fernando
Hello Escada,
You will find perfect solutions to your issue here:
I had also faced same issues in past.
Hope it helps.
Thanks,
Harshad M.
Assume you have Table1, with field A -> APrime, B -> BPrime ... D -> Dprime,
and Table2 with E -> EPrime and F -> Fprime
wouldn't a simple lookup table like
Table | From | To |
Table1 | A | APrime |
Table1 | B | BPrime |
Table1 | C | CPrime |
Table1 | D | DPrime |
Table2 | E | EPrime |
Table2 | F | FPrime |
work?
Tom
Here is a simple use of data set containing name from - to pairs, variable name and rename in a dataset to rename those variables in an exisitng dataset. Proc Datasets is used to modify existing data sets in place to rename variables or modify labels and formats.
data _null_;
set work.rename end=LastName;
/* this is the header part of proc datasets that is similar for each rename operation
change the name of the dataset in the modify statement*/
if _n_ = 1 then do;
Call execute ("Proc datasets library=MyLib nodetails nolist;");
Call execute ("modify MyDataset;");
/* starts rename*/
Call execute ("rename ") ;
end;
/* writes a list of the from - to name pairs using the data in work.rename*/
Call execute(catx(' ',name,' = ',newname)) ;
/* after the last pair end the rename clause*/
if LastName then do;
Call execute (";") ;
Call execute ("quit;");
end;
run;
You could have a variable in the working set with the dataset name and modify the code to use first. and last. notation based on the dataset .
Hello Escada,
You will find perfect solutions to your issue here:
I had also faced same issues in past.
Hope it helps.
Thanks,
Harshad M.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.