BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Moksha
Pyrite | Level 9

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Moksha
Pyrite | Level 9

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.

View solution in original post

7 REPLIES 7
Moksha
Pyrite | Level 9

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

Moksha
Pyrite | Level 9

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.

yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Moksha
Pyrite | Level 9

Thank you. I have tried this and it also worked.

ballardw
Super User

@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.

Moksha
Pyrite | Level 9

Thank you very much. I will definitely use this suggestion instead of new data set creation.

Tom
Super User Tom
Super User

If you just remove the label then places that display labels instead of names will display the name.

label emplid=' ';

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1959 views
  • 1 like
  • 4 in conversation