Hi All,
I have a data set "EMP" with column name ID. When I try to rename it to EMPID, it's not renaming.
Code:
data test;
set EMP (rename=(ID=EMPID));
run;
No, errors, "test" data set is getting created with all observations but without renaming the column ID.
I am not able to understand why it is not renaming the column.
I have tried like this also:
data test;
set EMP;
rename ID=EMPID;
run;
Please, help me to understand what could be the reason and how to resolve it.
When I try to check the following code, it is working:
data test1;
set sashelp.class;
run;
date test1_rename;
set test1 (rename=(NAME=EMPID));
run;
I have tried the following and it is working:
data test;
set EMP;
run;
data test;
set test (rename(ID=EMPID));
label EMPID='EMPID';
run;
and it worked.
I have just realized that using the column also has a label 'ID' and hence though internally it is renaming the column but since the label is not changed, it is displaying ID instead of EMPID.
Can anyone advise how to rename both column name and label?
Thanks
I have tried the following and it is working:
data test;
set EMP;
run;
data test;
set test (rename(ID=EMPID));
label EMPID='EMPID';
run;
and it worked.
Try this:
data test;
set sashelp.class(rename=(age=NEW_AGE));
label NEW_AGE="New label for New Age";
run;
Simplest way to see variables names and labels (if there are any) is to run:
proc contents data=test;
run;
Bart
Thank you. I have tried this and it also worked.
@Moksha wrote:
I have just realized that using the column also has a label 'ID' and hence though internally it is renaming the column but since the label is not changed, it is displaying ID instead of EMPID.
Can anyone advise how to rename both column name and label?
Thanks
Proc datasets will do both to a set in place. No need to create a new data set or take the chance of corrupting data that can happen with a logic error in a Data step.
Proc datasets library=yourlib nodetails nolist; modify somedatset; rename oldname=newname; label newname='New label text'; run; quit;
The nodetails and nolist options suppress printing some output to your results.
You can have multiple rename and label pairs in a single rename or label statement if desired. You can also change formats.
The procedure supports run group processing, such as modifying different data sets. So the procedure requires a Quit statement to end the procedure.
Thank you very much. I will definitely use this suggestion instead of new data set creation.
If you just remove the label then places that display labels instead of names will display the name.
label emplid=' ';
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.