I am new to SAS and perhaps naively trying to mimic building macros as function in SAS.
I have multiple macro variables which are initiated from a stored process. Some might have values, while others might be empty.
%let a1 = column_name1;
%let a2 = column_name2;
%let a3 = ;
%let col1 = &a1;
%let col2 = &a2;
%let col3 = &a3;
I want to use them in proc sql as:
proc sql;
create table some_table as
select
&col1 AS column1,
&col2 AS column2,
&col3 AS column3
from some_table;
quit;
However, this won't work for variables which are empty (&col3
). Therefore, I am trying to build some kind of function that will be wrapper around it. Something like:
%macro macro_return_string(macro_variable);
%if length(macro_variable) = 1 %then %do; /* if column_name# is not empty, then it len() is always >2 */
"";
%end;
%else %do;
macro_variable;
%end;
%mend macro_return_string;
So it will be used like:
%let col1 = macro_return_string(&a1); /* return column_name1 */
%let col2 = macro_return_string(&a2); /* return column_name2 */
%let col3 = macro_return_string(&a3); /* return "" */
Thanks for help!
A similar question was asked here but I cannot solve my problem from it.