Search code examples
sassas-macro

SAS - input list of tables as macro parameter


I would like to input a list of tables as a macro parameter.

Macro Code:

%MACRO Marco_Name ( Table_Name ) ;
    PROC SQL;    
    execute (
    select (owner ||'.'||table_name) as table_name from dba_tables 
    where table_name in (&Table_Name.)
   )
   QUIT;
%MEND Marco_Name ;

When I would invoke the macro with e.g.:

%Marco_Name ( Table_Name = 'table1', 'table2, 'table3')

I would like to the code to resolve to:

select (owner ||'.'||table_name) as table_name from dba_tables
where table_name in ('table1', 'table2, 'table3')

Solution

  • Welcome to the wonderful world of marco programming.

    The %STR macro function is used to wrap values containing commas that would otherwise confound the macro processor when passed as parameters.

    Invoke the macro as follows:

    %MyMacro ( Table_Name = %str ( 'table1', 'table2, 'table3' ) )