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!

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