BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aminkarimid
Lapis Lazuli | Level 10

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

3 REPLIES 3
ChrisHemedinger
Community Manager

Set:

 

Options VALIDVARNAME=ANY;

 

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

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
Reeza
Super User

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.

Gabrielle
SAS Employee

Wow.. thanks so much for this! I was stuck on this for a while wondering why I kept getting the same error and turns out, my problem wasn't really a problem to begin with because SAS already put the underscores for me.  

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 27869 views
  • 4 likes
  • 4 in conversation