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!
Ah yes that's the issue I had preset it to V7 in the previous step. Thanks for your help!
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 25. Read more here about why you should contribute and what is in it for you!
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.