Hi there,
Suppose I have the following macro
%MACRO MacroA(varA, varB);
I would like to create a new dataset that should be named varA_varB. For example, if varA is hello and varB is world, the datasource would be hello_world.
I tried &varA + "_" &varB in my macro code, but SAS doesn't like that. How can I achieve this?
Regards,
P.
&vara._&varb
You do not need an operator to combine strings generated by macro code. But you do need something to help the parser distinguish between whether you want the value of macro variable VARA or one named VARA_ . So you need to add a period before the _. Now if you really do need to have a period immediately after an expanded macro variable then you will have to type two as the first will be interpreted as ending the macro variable reference.
data class1 class2;
set sashelp.class;
run;
%macro macroa(vara,varb);
data &vara._&varb;
set &vara &varb;
run;
%mend;
%macroa(class1,class2)
proc print data=&syslast;run;
&vara._&varb
You do not need an operator to combine strings generated by macro code. But you do need something to help the parser distinguish between whether you want the value of macro variable VARA or one named VARA_ . So you need to add a period before the _. Now if you really do need to have a period immediately after an expanded macro variable then you will have to type two as the first will be interpreted as ending the macro variable reference.
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.
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.