Search code examples
sassas-macro

Inserting a table name into a string with SAS


I'm writing a macro in sas, that exports a file. I want the name of the file, to be the same as the name of the table in sas. So if i run:

%to_excel(my_table);

I want the file to be saved to "Q:/my_table.xlsx". Heres what I have so far:

%macro to_excel(tb);
proc export data=&tb
outfile=?????????????????
dbms = xlsx
replace;
run;
%mend;

Solution

  • You are almost there. Try this.

    %macro to_excel(tb);
    proc export data=&tb
    outfile="Q:/&tb..xlsx" 
    dbms = xlsx
    replace;
    run;
    %mend;
    
    %to_excel(my_table);