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=' ';

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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