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;
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.
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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.