Search code examples
sasmacrossas-macro

Macro not correct compiling?


I am creating this SAS macro to simulate the pandas python library, but I am already getting stuck fairly early on.

I will provide my code first and then explain.

%macro testt(database=);

%put ---------------------------------------------------------------;

%put --- Start of %upcase (&sysmacroname) macro;

%put ---;

%put --- Macro parameter values;

%put --- database       =       &database;

%put ---------------------------------------------------------------;

PROC SQL;
    CREATE TABLE &database AS
        SELECT 
                libname
            ,   memname
            ,   nvar
        FROM dictionary.tables
        WHERE libname = '&database';
RUN;
%mend;

%testt(database=DMAZRACT);

In this code I am trying to get each of the tables in a specific libref for further processing, but somehow when it runs. It outputs nothing. The query itself isn't wrong as when I remove the where statement it works perfectly fine.

Using %put doesn't show anything weird about the name either, but I tried %TRIM just incase. However that didn't really give me a solution either. It must be somewhere in where statement, but I am out of options.

Any help would be appreciated :)


Solution

  • Macro variables won't resolve inside single quotes. Try:

    WHERE libname = "&database" ;