BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
David_Billa
Rhodochrosite | Level 12

I want to rename the variable 'Expense' to 'VALUE_LC' and 'VALUE_TC' in one step. When I tried the code below, only the latest rename statement comes into effect.

 

'VALUE_LC' and 'VALUE_TC'  are different variables and it should have the values same as 'Expense' variable. Any help?

 

data HAVE;
set HAVE_A;
rename Expense=VALUE_LC;
rename Expense=VALUE_TC;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

After first rename done, the origin name does not exist;

you can do either:

value_lc = expense;
rename expense = value_tc;

or do:

value_lc = expense;
value_tc = expense;
drop expense;

or any other similar combination.

 

 

View solution in original post

2 REPLIES 2
Shmuel
Garnet | Level 18

After first rename done, the origin name does not exist;

you can do either:

value_lc = expense;
rename expense = value_tc;

or do:

value_lc = expense;
value_tc = expense;
drop expense;

or any other similar combination.

 

 

Kurt_Bremser
Super User

You misunderstand what RENAME does. Follow the link to the documentation, and you will see that the statement has no effect for the current data step code, only for the output dataset(s). Since the current name is still valid within the data step, you can use the RENAME again, but only the last one will have a lasting effect. And it only changes the name of an existing variable, but it does not create a new one. Therefore you cannot have two new variables for one that exists.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 956 views
  • 0 likes
  • 3 in conversation