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!
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!
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.
Ready to level-up your skills? Choose your own adventure.