BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to send email via sas that include some sentences in email body and also a table in body email.

This code is working 100% and add test to  body email.

/*****Add some text in body email***/
%macro send_Email_From_SAS;
filename outbox email
to=("Ron.Einstein@BankLeumi.co.il")
subject="Data sets check"
type="text/html"
from='Ron.Einstein@BankLeumi.co.il'
encoding="utf-8";


DATA _null_;
file outbox;
Put "היי,"//
 "Here are data sets list:"//
"r_r.&Overides_data_set.---טבלה ובה פירוט אובריידים--"//
"r_r.Batch_CS_Exp_Osek_vatik&ABT_mon."//
"r_r.Batch_CS_Exp_Prati_vatik&ABT_mon."//
"r_r.Batch_CS_Overide_Osek_vatik&ABT_mon."//
"r_r.Batch_CS_Overide_Prati_vatik&ABT_mon."//
"r_r.sofi_lak_Batch_CS&ABT_mon."//
"r_r.sofi_TZ_Batch_CS&ABT_mon."//
put ;
put ;
%mend send_Email_From_SAS;
%send_Email_From_SAS


 

When I try to add also tables to body then I get error


%macro send_Email_From_SAS;
filename outbox email
to=("Ron.Einstein@BankLeumi.co.il")
subject="Data sets check"
type="text/html"
from='Ron.Einstein@BankLeumi.co.il'
encoding="utf-8";


DATA _null_;
file outbox;
Put "היי,"//
 "Here are data sets list:"//
"r_r.&Overides_data_set.---טבלה ובה פירוט אובריידים--"//
"r_r.Batch_CS_Exp_Osek_vatik&ABT_mon."//
"r_r.Batch_CS_Exp_Prati_vatik&ABT_mon."//
"r_r.Batch_CS_Overide_Osek_vatik&ABT_mon."//
"r_r.Batch_CS_Overide_Prati_vatik&ABT_mon."//
"r_r.sofi_lak_Batch_CS&ABT_mon."//
"r_r.sofi_TZ_Batch_CS&ABT_mon."//
put ;
put ;


ods html body=outbox rs=none;
proc print data= temp noobs;
by model;
var  var_name OR_impact;
Run;
ods html  close;

%mend send_Email_From_SAS;
%send_Email_From_SAS


 

 

Error in Log

1                                                          The SAS System                               13:55 Monday, March 24, 2025

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program 1';
4          %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=SVG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         %macro HTML5AccessibleGraphSupported;
15             %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) >= 0 %then ACCESSIBLE_GRAPH;
16         %mend;
17         FILENAME EGHTML TEMP;
18         ODS HTML5(ID=EGHTML) FILE=EGHTML
19             OPTIONS(BITMAP_MODE='INLINE')
20             %HTML5AccessibleGraphSupported
NOTE: The ACCESSIBLE_GRAPH option is pre-production for this release.
21             ENCODING='utf-8'
22             STYLE=HTMLBlue
23             NOGTITLE
24             NOGFOOTNOTE
25             GPATH=&sasworklocation
26         ;
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
27         
28         
29         %macro send_Email_From_SAS;
30         filename outbox email
31         to=("Ron.Einstein@BankLeumi.co.il")
32         subject="Data sets check"
33         type="text/html"
34         from='Ron.Einstein@BankLeumi.co.il'
35         encoding="utf-8";
36         
37         
38         DATA _null_;
39         file outbox;
40         Put "היי,"//
41          "Here are data sets list:"//
42         "r_r.&Overides_data_set.---טבלה ובה פירוט אובריידים--"//
43         "r_r.Batch_CS_Exp_Osek_vatik&ABT_mon."//
44         "r_r.Batch_CS_Exp_Prati_vatik&ABT_mon."//
45         "r_r.Batch_CS_Overide_Osek_vatik&ABT_mon."//
46         "r_r.Batch_CS_Overide_Prati_vatik&ABT_mon."//
47         "r_r.sofi_lak_Batch_CS&ABT_mon."//
48         "r_r.sofi_TZ_Batch_CS&ABT_mon."//
49         put ;
50         put ;
51         
52         
53         ods html body=outbox rs=none;
54         proc print data= temp noobs;
55         by model;
56         var  var_name OR_impact;
2                                                          The SAS System                               13:55 Monday, March 24, 2025

57         Run;
58         ods html  close;
59         
60         %mend send_Email_From_SAS;
61         %send_Email_From_SAS
WARNING: Apparent symbolic reference OVERIDES_DATA_SET not resolved.
WARNING: Apparent symbolic reference ABT_MON not resolved.
WARNING: Apparent symbolic reference ABT_MON not resolved.
WARNING: Apparent symbolic reference ABT_MON not resolved.
WARNING: Apparent symbolic reference ABT_MON not resolved.
WARNING: Apparent symbolic reference ABT_MON not resolved.
WARNING: Apparent symbolic reference ABT_MON not resolved.
NOTE: Writing HTML Body file: OUTBOX
NOTE: Variable put is uninitialized.
ERROR: File is in use, .
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.13 seconds
      user cpu time       0.07 seconds
      system cpu time     0.02 seconds
      memory              4814.46k
      OS Memory           36000.00k
      Timestamp           03/24/2025 02:28:28 PM
      Step Count                        44  Switch Count  1
      Page Faults                       0
      Page Reclaims                     907
      Page Swaps                        0
      Voluntary Context Switches        52
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
      


NOTE: There were 92 observations read from the data set WORK.TEMP.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.08 seconds
      user cpu time       0.06 seconds
      system cpu time     0.00 seconds
      memory              2171.53k
      OS Memory           37280.00k
      Timestamp           03/24/2025 02:28:28 PM
      Step Count                        45  Switch Count  0
      Page Faults                       0
      Page Reclaims                     275
      Page Swaps                        0
      Voluntary Context Switches        3
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
      

Message sent
      To:          "Ron.Einstein@BankLeumi.co.il"
      Cc:          
      Bcc:         
      Subject:     Data sets check
      Attachments: 
3                                                          The SAS System                               13:55 Monday, March 24, 2025

62         
63         
64         
65         
66         %LET _CLIENTTASKLABEL=;
67         %LET _CLIENTPROCESSFLOWNAME=;
68         %LET _CLIENTPROJECTPATH=;
69         %LET _CLIENTPROJECTPATHHOST=;
70         %LET _CLIENTPROJECTNAME=;
71         %LET _SASPROGRAMFILE=;
72         %LET _SASPROGRAMFILEHOST=;
73         
74         ;*';*";*/;quit;run;
75         ODS _ALL_ CLOSE;
76         
77         
78         QUIT; RUN;
79         

 

 

 

1 REPLY 1
SASJedi
Ammonite | Level 13

Try putting the DATA step inside the ODS block, then use FILE PRINT; to direct the DATA step output text to ODS, something like this:

%macro send_Email_From_SAS;
filename outbox email
               to=("Ron.Einstein@BankLeumi.co.il")
               subject="Data sets check"
               type="text/html"
               from='Ron.Einstein@BankLeumi.co.il'
               encoding="utf-8"
;

ods html body=outbox rs=none;

DATA _null_;
   file PRINT;
   Put "היי,"//
    "Here are data sets list:"//
   "r_r.&Overides_data_set.---טבלה ובה פירוט אובריידים--"//
   "r_r.Batch_CS_Exp_Osek_vatik&ABT_mon."//
   "r_r.Batch_CS_Exp_Prati_vatik&ABT_mon."//
   "r_r.Batch_CS_Overide_Osek_vatik&ABT_mon."//
   "r_r.Batch_CS_Overide_Prati_vatik&ABT_mon."//
   "r_r.sofi_lak_Batch_CS&ABT_mon."//
   "r_r.sofi_TZ_Batch_CS&ABT_mon."////
run;

proc print data= temp noobs;
   by model;
   var  var_name OR_impact;
run;
ods html  close;
%mend send_Email_From_SAS;

%send_Email_From_SAS

 

Check out my Jedi SAS Tricks for SAS Users

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 618 views
  • 1 like
  • 2 in conversation