I am new to programming in sas and I am creating a daily email report in which I want a file to be attached, showing me some lines of text with macro variables in the body of the message and also attaching the content of a table in the body of the message, so you don't have to open it.
I have achieved everything but the problem is that it sends me 2 emails automatically, 1 with the attached file and the lines of text and another with the image of the table that I want it to show me in the body of the message, how could I solve this so that I I sent it in 1 email only? someone knows? I have seen other methods out there using proc sql and writing the text lines there, but I think that with this I cannot incorporate macro variables to the text lines, so this is important.
Here is the code that I have tested.
```
proc import datafile = "xx/xxx/xxx"
out = TEST
dbms = dlm
replace;
delimiter = '09'x;
getnames= NO;
run;
proc options option=emailsys;
run;
filename outbox email "xxxx@xxx.com";
%MACRO email2;
data _null_;
file outbox
to=("xxxx@xxxxx")
cc=("xxxxxx@xxxxx.com")
subject="xxxxx"
attach = "xxxx/xxxx/xxxx/xxx"
;
put 'xxxxxxx';
put "xxxxxxxx ¯o1 xxxxxx.";
put "xxxxxxxx ¯o2 xxxxxx.";
put "xxxxxxxx ¯o3 xxxxxx.";
put "xxxxxxxx ¯o4 xxxxxx.";
put "xxxxxxxx ¯o5 xxxxxx.";
data _null_;
file outbox;
put 'Test.';
run; quit;
FILENAME outbox EMAIL
to=("xxxxx@xxx.com")
subject="test"
CONTENT_TYPE="text/html";
ODS LISTING CLOSE;
ODS HTML BODY=outbox;
PROC PRINT DATA=TEST;
RUN;
ODS HTML CLOSE;
ODS LISTING;
run;
%mend email2;
%email2;
```
If someone could help me find a solution to send this in 1 email with the macrovariables in the text lines included, I would be very grateful
Hello,
Have a look at this section (same Communities Library article) :
You need to write a PROC REPORT or PROC PRINT and use ODS HTML output destination.
Then your data is displayed in the body of the mail.
Cheers,
Koen
Hello,
Check out this :
How to send email using SAS?
Posted 06-10-2021 06:03 PM | by ChrisHemedinger
https://communities.sas.com/t5/SAS-Communities-Library/How-to-send-email-using-SAS/ta-p/746523
Cheers,
Koen
Hello,
Have a look at this section (same Communities Library article) :
You need to write a PROC REPORT or PROC PRINT and use ODS HTML output destination.
Then your data is displayed in the body of the mail.
Cheers,
Koen
Thank you very much, it works.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.