Hi, I am trying to send out an e-mail using sas and would like to be able to attached more than one attachment to that email. I created a list of the file names to use in a loop in the attachment field. I think I am missing something...any suggestions...thanks.
PROC SQL NOPRINT;
CREATE TABLE FILE_LIST AS
SELECT
(HINS.FILENAME || "Report" || " (" || HINS.RUNDATE1 || ")") AS FILENAME1
FROM WORK.HINS;
QUIT;
DATA _NULL_;
SET FILE_LIST END=LAST;
IF _N_=1 THEN DO;
CALL EXECUTE('DATA _NULL_');
FILENAME mail EMAIL
TO = "Lisa345@yahoo.com"
FROM = "Mike12@yahoo.com"
BCC = "Mike12@yahoo.com"
SUBJECT = "Report %sysfunc(today(), date9.)"
IMPORTANCE='LOW'
ATTACH=("U:\Data Programs\DCT\("'||STRIP(FILENAME1)||'"')");
END;
ELSE DO;
CALL EXECUTE ("'||STRIP(FILENAME1)||'");
END;
IF LAST THEN DO;
CALL EXECUTE ('DATA _NULL_');
FILE mail;
PUT "Hi Lisa,";
PUT " ";
PUT "This is test";
PUT " ";
PUT "Thanks,";
END;
RUN;
QUIT;
Recommend you extract from your overall SAS code (shared in the post) an explicit SAS program script that demonstrates what you wish to accomplish -- then slowly amend the SAS execution code to piece-by-piece add in each automation-aspect you are wanting to have work.
From what you contributed, there are multiple instances of missing semi-colon characters (code line termination) which will influence the success/failure.
Desk-checking your SAS program is going to be a good start....only then after you get some SAS log results, you should consider sharing this additional information -- rather than just the SAS code you would like to think will work.
Essentially, start with the simplest of intentions with what you are trying to achieve and then sculpt the masterpiece iteratively....
Hi...Here the log information:
59 DATA _NULL_;
60 SET FILE_LIST END=LAST;
61 IF _N_=1 THEN DO;
62 CALL EXECUTE('data _null_');
63 FILENAME mail EMAIL
64 TO = "Lisa345@yahoo.ca"
65 FROM = "Mike12@yahoo.ca"
66 BCC = "Mike12@yahoo.ca"
67 SUBJECT = "Report %sysfunc(today(), date9.)"
68 IMPORTANCE='LOW'
69 ATTACH=("U:\Data Programs\DCT\("'||STRIP(FILENAME1)||'"')");
70 END;
71 ELSE DO;
72 CALL EXECUTE ("'||STRIP(FILENAME1)||'");
73 END;
74 IF LAST THEN DO;
75 CALL EXECUTE(')
76 DATA _NULL_;
77 FILE mail
78 PUT "Hi Lisa,";
79 PUT " ";
80 PUT "This is test";
81 PUT " ";
82 PUT "Thanks,";
The SAS System
83
84
85 END;
86 RUN;
87
88
89
90 GOPTIONS NOACCESSIBLE;
91 %LET _CLIENTTASKLABEL=;
92 %LET _CLIENTPROJECTPATH=;
93 %LET _CLIENTPROJECTNAME=;
94 %LET _SASPROGRAMFILE=;
95
96 ;*';*";*/;quit;run;
_ ____
79 180
ERROR 79-322: Expecting a ).
ERROR 180-322: Statement is not valid or it is used out of proper order.
Suggest you run again with OPTIONS parameters that will increase the useful SAS log program compilation diagnostics, OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MLOGIC; -- some of which would not necessarily apply here, without MACRO usage.
Also, as was suggested, strip-out all but the bare-essential SAS processing to generate the EMAIL -- that would be the "resuting code" generated from the CALL EXECUTE -- no surrounding DATA step. And then work your way backwards, one step at a time.
And, your use of FILENAME is not part of the CALL EXECUTE, in case that's what you intended.
Reviewing CALL EXECUTE, that SAS code will be compiled and executed only after the current DATA step completes.
Strongly suggest you start simple then increase complexity, only after suitable self-initiated desk-checking.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.