BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I run this code to send and email from SAS .

The email should contain few sentences in body mail and summary tables in body mail.

The email should also have attached XLSX    file (sashelp.cars ).

What is the reason that this code don't produce the attach file to the email???

Proc export data=sashelp.cars   
outfile="/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/cars.xlsx"
dbms=xlsx replace;
sheet="bakara_Yomit_Files";
Run;
 

title;
footnote;
FILENAME myemail EMAIL  
TO="Dave@gmail.com"
FROM="Dave@gmail.com"
SUBJECT="Ron Report" 
CONTENT_TYPE="text/html" 
encoding="utf-8"
attach=("/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/cars.xlsx" content_type="excel");
ODS LISTING CLOSE;
ODS HTML BODY=mail;
proc odstext;
heading 'Cars Report' /Style=Header {fontsize=16pt  color=blue  fontstyle=italic};
p 'Hello';
p 'Here is cars report';
p " ";
p "regards";
p "Dave";
run;
title;
footnote;
Title 'Cars';
proc report data = SasHelp.Cars(obs = 5) split = "*";
column Type MPG_Ratio MPG_City MPG_Highway;
define Type / display ;
define MPG_City / display;
define MPG_Highway / display;
define MPG_Ratio / computed 'City/Highway' format = 4.2;
compute MPG_Highway;  
MPG_Ratio = MPG_City/MPG_Highway;
endcomp;
run;
title;
footnote;
Title 'class';
proc report data = SasHelp.class(obs = 5);
run;
ODS HTML CLOSE;
ODS LISTING;
4 REPLIES 4
ballardw
Super User

Show us the log for the part of your code that you think is supposed to attach the file.

 

 

Ronein
Meteorite | Level 14
Proc export data=sashelp.cars   
outfile="/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/cars.xlsx"
dbms=xlsx replace;
sheet="bakara_Yomit_Files";
Run;
 

title;
footnote;
FILENAME myemail EMAIL  
TO="Ron.Einstein@BankLeumi.co.il"
FROM="Ron.Einstein@BankLeumi.co.il"
SUBJECT="Ron Report" 
CONTENT_TYPE="text/html" 
encoding="utf-8"
attach=("/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/cars.xlsx" content_type="excel");
ODS LISTING CLOSE;
ODS HTML BODY=mail;
proc odstext;
heading 'Cars Report' /Style=Header {fontsize=16pt  color=blue  fontstyle=italic};
p 'Hello';
p 'Here is cars report';
p " ";
p "regards";
p "Dave";
run;
title;
footnote;
Title 'Cars';
proc report data = SasHelp.Cars(obs = 5) split = "*";
column Type MPG_Ratio MPG_City MPG_Highway;
define Type / display ;
define MPG_City / display;
define MPG_Highway / display;
define MPG_Ratio / computed 'City/Highway' format = 4.2;
compute MPG_Highway;  
MPG_Ratio = MPG_City/MPG_Highway;
endcomp;
run;
title;
footnote;
Title 'class';
proc report data = SasHelp.class(obs = 5);
run;
ODS HTML CLOSE;
ODS LISTING;

Error in Log

1                                                          The SAS System                                10:54 Tuesday, June 4, 2024

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=PNG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         FILENAME EGSR TEMP;
15         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16             STYLE=HTMLBlue
17             STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HTMLBlue.css")
18             NOGTITLE
19             NOGFOOTNOTE
20             GPATH=&sasworklocation
21             ENCODING=UTF8
22             options(rolap="on")
23         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24         
25         GOPTIONS ACCESSIBLE;
26         
27         title;
28         footnote;
29         FILENAME myemail EMAIL
30         TO="Ron.Einstein@BankLeumi.co.il"
31         FROM="Ron.Einstein@BankLeumi.co.il"
32         SUBJECT="Ron Report"
33         CONTENT_TYPE="text/html"
34         encoding="utf-8"
35         /*attach=("/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/cars.xlsx" content_type="excel")*/
36         ;
37         ODS LISTING CLOSE;
38         ODS HTML BODY=mail;
NOTE: Writing HTML Body file: MAIL
ERROR: No logical assign for filename MAIL.
ERROR: No body file. HTML output will not be created.
39         proc odstext;
40         heading 'Cars Report' /Style=Header {fontsize=16pt  color=blue  fontstyle=italic};
41         p 'Hello';
42         p 'Here is cars report';
43         p " ";
44         p "regards";
45         p "Dave";
46         run;
NOTE: PROCEDURE ODSTEXT used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              71.90k
      OS Memory           24480.00k
      Timestamp           06/04/2024 10:57:15 AM
      Step Count                        13  Switch Count  0
2                                                          The SAS System                                10:54 Tuesday, June 4, 2024

      Page Faults                       0
      Page Reclaims                     9
      Page Swaps                        0
      Voluntary Context Switches        3
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
      

47         title;
48         footnote;
49         Title 'Cars';
50         proc report data = SasHelp.Cars(obs = 5) split = "*";
51         column Type MPG_Ratio MPG_City MPG_Highway;
52         define Type / display ;
53         define MPG_City / display;
54         define MPG_Highway / display;
55         define MPG_Ratio / computed 'City/Highway' format = 4.2;
56         compute MPG_Highway;
57         MPG_Ratio = MPG_City/MPG_Highway;
58         endcomp;
59         run;

NOTE: Multiple concurrent threads will be used to summarize data.
NOTE: There were 5 observations read from the data set SASHELP.CARS.
NOTE: PROCEDURE REPORT used (Total process time):
      real time           0.01 seconds
      user cpu time       0.01 seconds
      system cpu time     0.00 seconds
      memory              8438.12k
      OS Memory           31668.00k
      Timestamp           06/04/2024 10:57:15 AM
      Step Count                        14  Switch Count  0
      Page Faults                       0
      Page Reclaims                     1754
      Page Swaps                        0
      Voluntary Context Switches        30
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
      

60         title;
61         footnote;
62         Title 'class';
63         proc report data = SasHelp.class(obs = 5);
64         run;

NOTE: Multiple concurrent threads will be used to summarize data.
NOTE: There were 5 observations read from the data set SASHELP.CLASS.
NOTE: PROCEDURE REPORT used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              7685.28k
      OS Memory           30644.00k
      Timestamp           06/04/2024 10:57:16 AM
      Step Count                        15  Switch Count  0
3                                                          The SAS System                                10:54 Tuesday, June 4, 2024

      Page Faults                       0
      Page Reclaims                     1442
      Page Swaps                        0
      Voluntary Context Switches        22
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
      

65         ODS HTML CLOSE;
66         ODS LISTING;
67         
68         GOPTIONS NOACCESSIBLE;
69         %LET _CLIENTTASKLABEL=;
70         %LET _CLIENTPROCESSFLOWNAME=;
71         %LET _CLIENTPROJECTPATH=;
72         %LET _CLIENTPROJECTPATHHOST=;
73         %LET _CLIENTPROJECTNAME=;
74         %LET _SASPROGRAMFILE=;
75         %LET _SASPROGRAMFILEHOST=;
76         
77         ;*';*";*/;quit;run;
78         ODS _ALL_ CLOSE;
79         
80         
81         QUIT; RUN;
82         
ballardw
Super User

I think part of the issue is not referencing the correct Fileref

29         FILENAME myemail EMAIL
30         TO="Ron.Einstein@BankLeumi.co.il"
31         FROM="Ron.Einstein@BankLeumi.co.il"
32         SUBJECT="Ron Report"
33         CONTENT_TYPE="text/html"
34         encoding="utf-8"
35         /*attach=("/usr/local/SAS/SASUsers/LabRet/UserDir/udclk79/cars.xlsx" content_type="excel")*/
36         ;
37         ODS LISTING CLOSE;
38         ODS HTML BODY=mail;

The error tells you the fileref Mail is not assigned, so no Html output is generated and I suspect means there isn't anything in the email actually attaching.

Mazi
Pyrite | Level 9
ods excel file = "~/test.xlsx";
	proc print data=sashelp.cars;
	run;
ods excel close;


proc copy in=sashelp out=work;
	select cars;
run;


FILENAME mail EMAIL 
TO=("xxx@email.com")
FROM=("xxxx@email.com")
SUBJECT="Cars"
encoding='utf-8'
CONTENT_TYPE="text/html"
encoding="utf-8"
attach=(
"%sysfunc(pathname(work))/cars.sas7bdat" 
content_type="application/SAS7BDAT" "~/test.xlsx" content_type="excel"
)
;

data _null_;
	file mail;
	Put "Testing";
	Put "Testing";
run;

Can you try this?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 265 views
  • 0 likes
  • 3 in conversation