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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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.  

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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