How to add multiple sheets to excel in enterprise-SAS?

Viewed 237

I use the following code to output specific table/data to a sheet and send it to my email. The data is called "cat" but I also have "dog" and "cow" data sets or tables if you like. Can you please advise how to modify my code in order to get "cat" data on one sheet, "dog" on another and "cow" on another and then send it to my email?

..some code here....

...ending of the code generates the file and email:

proc export data= cat
            outfile= "&location.cat.csv"
            label
            replace
            dbms=csv;
run;

OPTIONS EMAILSYS=SMTP;

filename mymail email to=('west@west.com')
                            subject="cat"
                attach=("&location.cat.csv")
                type = 'text/html';
    
   *Produce the email body, then send the mail*;
   ods listing close;
   ods html body = mymail rs=none;

    proc print 
    noobs data = cat;
    title1 "cat";
    run;

   ODS HTML CLOSE;
2 Answers

If you cannot find a solution to "sheets" try adding multiple workbooks into one email:

proc export data= cat
            outfile= "&location.cat.csv"
            label
            replace
            dbms=csv;
run;

proc export data= dog
            outfile= "&location.dog.csv"
            label
            replace
            dbms=csv;
run;

proc export data= cow
            outfile= "&location.cow.csv"
            label
            replace
            dbms=csv;
run;

OPTIONS EMAILSYS=SMTP;

filename mymail email to=('west@west.com')
                            subject="cat"
                attach=("&location.cat.csv")
                attach=("&location.dog.csv")
                attach=("&location.cow.csv")
                type = 'text/html';

   ods listing close;
   ods html body = mymail rs=none;

   ODS HTML CLOSE;

CSV is not an excel workbook. You can export to multiple CSVs as the other answer shows, or you can export to an excel workbook using DBMS=XLSX and then using the SHEET= option.

Related