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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
PierreYvesILY
Pyrite | Level 9

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
PierreYvesILY
Pyrite | Level 9

hi Paige,

 

I used the version " and type = 'num' " and it worked perfectly.

 

thanks a lot,

regards

PY

Tom
Super User Tom
Super User

Why not just tweek the WHERE clause?

where libname = 'WORK' and memname = "FICHIER_1"
  and upcase(name) not in ('VAR1','VAR2','VAR3')
PierreYvesILY
Pyrite | Level 9

I also tested this code version with success.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 747 views
  • 2 likes
  • 3 in conversation