Rename excel column name

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

Rename excel column name

Hi, i have an xls file from which records needs to be extracted for loading to DB table. SAS by default has provided an extraction script which uses XLS engine for importing the data. I require the column names in the excel to be renamed before the extraction script is run. Is there any sas code to rename the column on the file. Any pointers to this would be helpful


Accepted Solutions
Solution
‎09-12-2017 07:16 AM
Super User
Posts: 10,557

Re: Rename excel column name

Posted in reply to Anand6666

You have two possibilities:

- set options validvarname=v7; this will force proc import to create names that comply with SAS standards.

- or use (eg) 'Name of Individual or Entity'n as the variable name in the rename statement.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Super User
Posts: 10,557

Re: Rename excel column name

Posted in reply to Anand6666

Use PROC DATASETS. In a MODIFY block for your imported dataset, use the RENAME statement to rename the variables.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 23

Re: Rename excel column name

Posted in reply to KurtBremser

Thanks Kurt for the update, got a lead to explore. After importing the excel data into sas dataset, i tried the renaming option but column name contains space between it instead of '_' hence causing the code to fail.

Error: Expecting an =.

 

is there any way i can rename the column - Name type -> Name_type.

Have attached a screenshot of the column name for reference.

Solution
‎09-12-2017 07:16 AM
Super User
Posts: 10,557

Re: Rename excel column name

Posted in reply to Anand6666

You have two possibilities:

- set options validvarname=v7; this will force proc import to create names that comply with SAS standards.

- or use (eg) 'Name of Individual or Entity'n as the variable name in the rename statement.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 23

Re: Rename excel column name

Posted in reply to KurtBremser

Thanks a ton Kurt for the quick response . I tried both approaches and both worked fine .

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 459 views
  • 1 like
  • 2 in conversation