Desktop productivity for business analysts and programmers

Is it possible to rename variable name in a sas dataset if we know part of the variable name

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

Is it possible to rename variable name in a sas dataset if we know part of the variable name

Hi ,

 

I have a sas dataset with some columns. I need to change the variable name of the dataset as that variable name is producing an error when i am trying to register the table in metadata. How can i rename the variable if i know only part of the variable name.

 


Regards,

Naveen


Accepted Solutions
Solution
‎05-31-2016 09:40 AM
Esteemed Advisor
Posts: 6,690

Re: Is it possible to rename variable name in a sas dataset if we know part of the variable name

Do the following in a program window first:

data dataset;
set dataset;
rename 'test?_name'n = test_name;
run;

You should then be able to register the dataset.

It may be necessary to copy the variable name from the proc contents output and paste it into the string delimited by the single quotes, to avoid problems by different character representations.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Esteemed Advisor
Posts: 5,198

Re: Is it possible to rename variable name in a sas dataset if we know part of the variable name

What do you mean that you only know a part of the name?

What kind of error do you get during registration?

Please show the real life example/elaborate more about the situation.

Data never sleeps
Contributor
Posts: 50

Re: Is it possible to rename variable name in a sas dataset if we know part of the variable name

ERROR: Character is unclassifiable.

 

I think this is because of column name. so only i was asking how to rename a column. On seaching column name using proc content i got name as 

 

test?_name of type num and length 8.

 

Solution
‎05-31-2016 09:40 AM
Esteemed Advisor
Posts: 6,690

Re: Is it possible to rename variable name in a sas dataset if we know part of the variable name

Do the following in a program window first:

data dataset;
set dataset;
rename 'test?_name'n = test_name;
run;

You should then be able to register the dataset.

It may be necessary to copy the variable name from the proc contents output and paste it into the string delimited by the single quotes, to avoid problems by different character representations.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Esteemed Advisor
Posts: 5,198

Re: Is it possible to rename variable name in a sas dataset if we know part of the variable name

If this is a SAS dataset, you generally use PROC DATSETS to do this.

But you should be able to see the actual columns name if you issue a non-mete libname to the loaction of your SAS data files.

What is the setting of validvarname in the environment? And where did this data got created?

Data never sleeps
Contributor
Posts: 50

Re: Is it possible to rename variable name in a sas dataset if we know part of the variable name

[ Edited ]

how to check the setting of validvarname. Sorry i have not changed any system settings in my environment. So i am not sure which autoexec file should i check

Esteemed Advisor
Posts: 5,198

Re: Is it possible to rename variable name in a sas dataset if we know part of the variable name

It's paramount to understand how and where system options are set.
Proc options;
Run;
Will give you the current setting in the workspace server (given execution in EG or DI Studio).
The setting "could" be different in the Metadata server, but that's unlikely if you haven't changed anything since initial setup.
Data never sleeps
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 738 views
  • 1 like
  • 3 in conversation