hello,
I used the following code to rename variables and add a suffix to all variable names of my dataset.
proc sql noprint; /* Variablen umbennennen */
select cats(name,'=',name,'_&Jahr11.')
into :list
separated by ' '
from dictionary.columns
where libname = 'WORK' and memname = "FICHIER_1";
quit;
proc datasets library = work nolist;
modify fichier_1;
rename &list;
quit;
proc contents data = work.fichier_1 ; run;
The variables are correctly renamed, however a few of them didn't need a rename.
So, I'm asking for help to:
option 1: modify the above code in order to exclude a limited list of variable names to be renamed
option 2: remove the suffix from the names of this limited list of variable names.
What can I do best?
Thanks for your help
On the contrary, ALL variables that need to be renamed are numeric.
from dictionary.columns
where libname = 'WORK' and memname = "FICHIER_1" and type='num';
For future reference, you can look inside the dictionary.columns data set to see what is in there in case you ever need to use other columns for some purpose; in the SAS Explorer window this dictionary.columns data set is called SASHELP.VCOLUMN.
@PierreYvesILY wrote:
The variables are correctly renamed, however a few of them didn't need a rename.
Please explain this part further.
Please show us your LOG (the entire log, not just the error messages) by copying the text of the log and pasting it into the window that appears when you click on the {i} icon. Do not paste the log directly into the reply window.
hello Paige,
the code works, so there are no errors in the log. The log contains too many infos that cannot be displayed out of the company, I cannot send it.
This code renames ALL variables names, and I want to limit this: 6 different variables don't need to be renamed (I want to keep them as they are named). All of them are alphanumeric. On the contrary, ALL variables that need to be renamed are numeric.
Let's say, I have the following variables in the dataset: STUFE REGION AGENCY PRODUCTION RATE GROWTH ...
[ ALPHANUMERIC NUMERIC ] (the real number of numeric variables is high)
I want to add a macrovariable _&Jahr11. to all numeric variable names, and obtain:
STUFE REGION AGENCY PRODUCTION_&Jahr11. RATE_&Jahr11. GROWTH_&Jahr11. ...
I hope the context is clear now.
On the contrary, ALL variables that need to be renamed are numeric.
from dictionary.columns
where libname = 'WORK' and memname = "FICHIER_1" and type='num';
For future reference, you can look inside the dictionary.columns data set to see what is in there in case you ever need to use other columns for some purpose; in the SAS Explorer window this dictionary.columns data set is called SASHELP.VCOLUMN.
hi Paige,
I used the version " and type = 'num' " and it worked perfectly.
thanks a lot,
regards
PY
Why not just tweek the WHERE clause?
where libname = 'WORK' and memname = "FICHIER_1"
and upcase(name) not in ('VAR1','VAR2','VAR3')
I also tested this code version with success.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.