BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Abelp9
Quartz | Level 8

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 &macro1 xxxxxx.";
   put "xxxxxxxx &macro2 xxxxxx.";
   put "xxxxxxxx &macro3 xxxxxx.";
   put "xxxxxxxx &macro4 xxxxxx.";
   put "xxxxxxxx &macro5 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

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

Hello,

 

Have a look at this section (same Communities Library article) :

How to format your email with ODS in SAS?

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

View solution in original post

4 REPLIES 4
sbxkoenk
SAS Super FREQ

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

Abelp9
Quartz | Level 8
thank you very much for your contribution, in my case I want to import a table into the body of the mail, not an image, that information appears in the document you have sent me (I have not seen how to incorporate the content of a table in the body of the message)
sbxkoenk
SAS Super FREQ

Hello,

 

Have a look at this section (same Communities Library article) :

How to format your email with ODS in SAS?

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

Abelp9
Quartz | Level 8

Thank you very much, it works.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 4622 views
  • 1 like
  • 2 in conversation