Renaming a variable that is more than 32 characters

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Renaming a variable that is more than 32 characters

I have been given a dataset to analyze and some of the variable names are longer than 32 characters and thus I get error messages when I am trying to analyze these variables. How do I change the variable name to be less than 32 characters?

I have tried this:

data hemo.play;

set hemo.hemo_mrg2 (RENAME=(WhiteAfricanAmericanAmericanIndianPacificIslanderOther=Race));

Run;

I still get the same error message that the variable exceeds the 32 character limit.

Thank you for the help.


Accepted Solutions
Solution
‎02-24-2014 05:30 PM
Valued Guide
Posts: 2,174

Re: Renaming a variable that is more than 32 characters

@uwmsasuser

please run the following code replacing "your.data" with the name of your data.

PROC CONTENTS VARNUM DATA= your.data ;

RUN;

That should create a report indicating your column names.

View solution in original post


All Replies
Esteemed Advisor
Posts: 7,296

Re: Renaming a variable that is more than 32 characters

What kind of dbms is the library hemo?  If it is pointing to a library of SAS datasets, the name can't be more than 32 characters long to begin with.

Occasional Contributor
Posts: 12

Re: Renaming a variable that is more than 32 characters

It is a SAS library. The data was imported from Excel and the variables were imported just as they were in excel so I have variable names in my SAS dataset that are more than 32 characters. I can view the data within those variables when I look at the data table but cannot manipulate the variable in anyway since the name is too long.

Respected Advisor
Posts: 4,609

Re: Renaming a variable that is more than 32 characters

When I import an Excel column named "WhiteAfricanAmericanAmericanIndianPacificIslanderOther" into SAS, it gets the SAS variable name "WhiteAfricanAmericanAmericanIndi" and label "WhiteAfricanAmericanAmericanIndianPacificIslanderOther"

PG

PG
Grand Advisor
Posts: 10,223

Re: Renaming a variable that is more than 32 characters

Perhaps the LABEL is that long? When viewing the table click on the column header to display variable properties and see if you have a shorter variable NAME that possibly has spaces replaced with _, and a Label the full length of the original column heading.

Solution
‎02-24-2014 05:30 PM
Valued Guide
Posts: 2,174

Re: Renaming a variable that is more than 32 characters

@uwmsasuser

please run the following code replacing "your.data" with the name of your data.

PROC CONTENTS VARNUM DATA= your.data ;

RUN;

That should create a report indicating your column names.

Occasional Contributor
Posts: 14

Re: Renaming a variable that is more than 32 characters

 

 

I can't see how this answers the question?

 

The OPs problem is that a variable name is too long.

Running a proc contents will list the variables, but not change the fact a variable name is too long. After running proc contents it is still not possible to rename the variable.

 

What am I missing here?

 

 

Occasional Contributor
Posts: 12

Re: Renaming a variable that is more than 32 characters

Thank you for the help. My column name was showing the full name which was the LABEL and not the variable name. You are correct that SAS was truncating the variable. Thank you all!

☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 5194 views
  • 3 likes
  • 6 in conversation