Rename Variable with Space

Accepted Solution Solved
Reply
Regular Contributor
Posts: 166
Accepted Solution

Rename Variable with Space

Hello everybody;

I have existing dataset sampledata87_02 which has space in variables name like below;

 

Trade Date

 

Now I am trying to using this dataset and wants to rename all above variables... . How can I do that?

 

I am using this logic but its not working.

 

 

data sampledata87_02;
	set sampledata87_02;
	rename 
	'Trade Date'n=Trade_Date;
run;

 

 

The log is:

 

168  data sampledata87_02;
169      set sampledata87_02;
170      rename
171      'Trade Date'n=Trade_Date;
         -------------
         24
ERROR 24-322: Variable name is not valid.

172      run;

WARNING: The variable Trade Date in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.SAMPLEDATA87_02 may be incomplete.  When this step was stopped there
         were 0 observations and 18 variables.
WARNING: Data set WORK.SAMPLEDATA87_02 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds

 Thanks.

 


Accepted Solutions
Solution
‎05-25-2017 06:54 AM
Super User
Posts: 23,323

Re: Rename Variable with Space

Posted in reply to aminkarimid

Make sure you're seeing the variable name, not label. 

The label likely has spaces but the variable name may be automatically converted to the underscore. Run a PROC CONTENTS to see the labels vs data set name.

View solution in original post


All Replies
Community Manager
Posts: 3,382

Re: Rename Variable with Space

Posted in reply to aminkarimid

Set:

 

Options VALIDVARNAME=ANY;

 

That's one of my subtopics in this blog post about downloading/converting files from the web.

Solution
‎05-25-2017 06:54 AM
Super User
Posts: 23,323

Re: Rename Variable with Space

Posted in reply to aminkarimid

Make sure you're seeing the variable name, not label. 

The label likely has spaces but the variable name may be automatically converted to the underscore. Run a PROC CONTENTS to see the labels vs data set name.

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 1599 views
  • 1 like
  • 3 in conversation