BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
qw213
Calcite | Level 5

I am trying to rename my columns in a macro but my desired column names have spaces and special characters in them. (e.g. change column name aaa to aaa $)The code with nliteral works fine outside of the macro but when running in the macro it produces error: 

 

ERROR 24-322: Variable name is not valid.

 

My code is below

 

data names;
input name_old $3. name_new & $5.;
datalines;
aaa aaa $
bbb bbb $
;
run;

%macro process; PROC SQL; SELECT cats(name_old,' = ',nliteral(name_new)) INTO :rename separated by ' ' FROM names; quit; data data2; SET data1 (rename=(&rename)); run; %mend; %process;

 

I need to write in the macro because I have to perform this action to proceed to my next desired output for multiple data sets.

 

Thanks for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @qw213,

 

Did you set the required system option?

options validvarname=any;

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @qw213,

 

Did you set the required system option?

options validvarname=any;
qw213
Calcite | Level 5

Ah yes that's the issue I had preset it to V7 in the previous step. Thanks for your help!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 3949 views
  • 0 likes
  • 2 in conversation