DATA Step, Macro, Functions and more

re: email with multiple attachments

Reply
Regular Contributor
Posts: 229

re: email with multiple attachments

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;

Super Contributor
Super Contributor
Posts: 3,174

Re: re: email with multiple attachments

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....

Regular Contributor
Posts: 229

Re: re: email with multiple attachments

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.

         

Super Contributor
Super Contributor
Posts: 3,174

Re: re: email with multiple attachments

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.

Ask a Question
Discussion stats
  • 3 replies
  • 305 views
  • 0 likes
  • 2 in conversation