-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathemail.sas
109 lines (89 loc) · 3.64 KB
/
email.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
%macro email(from=,to=,cc=,subject=,attach=,message=) / des="Send email with attachment";
/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: Email
Author: Chris Swenson
Created: 2010-09-22
Purpose: Send an email with an attachment
Arguments: from - e-mail address of the sender
to - e-mail address of the recipient
cc - e-mail address of the recipient to recieve a copy
subject - e-mail subject
attach - name, path, and extension of the attached file
message - body contents, in quotes
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/
%if %superq(to)=%str() %then %do;
%put %str(E)RROR: No TO address specified.;
%return;
%end;
%if %superq(subject)=%str() %then %do;
%put %str(E)RROR: No SUBJECT specified.;
%return;
%end;
%if %superq(message)=%str() %then %do;
%put %str(E)RROR: No MESSAGE specified.;
%return;
%end;
%if %nrbquote(%substr(%superq(message), 1, 1)) ne %str(%") %then %do;
%if %nrbquote(%substr(%superq(message), 1, 1)) ne %str(%') %then %do;
%put %str(E)RROR: Please enclose message in qoutes.;
%return;
%end; %end;
%if %nrbquote(%substr(%superq(message), %length(%superq(message)), 1)) ne %str(%") %then %do;
%if %nrbquote(%substr(%superq(message), %length(%superq(message)), 1)) ne %str(%') %then %do;
%put %str(E)RROR: Please enclose message in qoutes.;
%return;
%end; %end;
%if %superq(from) ne %str() %then %do;
%if %sysfunc(countw(%superq(from), %str( )))>1 %then %do;;
%put %str(E)RROR: Only 1 from address allowed.;
%return;
%end;
%end;
/* Determine count of arguments */
%local tocount cccount attachcount tonext ccnext attachnext toc ccc attachc;
%let tocount=%sysfunc(countw(%superq(to), %str( )));
%if %superq(cc) ne %str() %then %let cccount=%sysfunc(countw(%superq(cc), %str( )));
%if %superq(attach) ne %str() %then %let attachcount=%sysfunc(countw(%superq(attach), %str( )));
filename mymail email "NULL"
%if %superq(from) ne %str() %then %do;
from="%superq(from)"
%end;
to=(
%do toc=1 %to &tocount;
%let tonext=%scan(%superq(to), &toc, %str( ));
"%superq(tonext)"
%end;
)
%if %superq(CC) ne %str() %then %do;
cc=(
%do ccc=1 %to &cccount;
%let ccnext=%scan(%superq(cc), &ccc, %str( ));
"%superq(ccnext)"
%end;
)
%end;
subject="%superq(subject)"
%if %superq(attach) ne %str() %then %do;
attach=(
%do attachc=1 %to &attachcount;
%let attachnext=%scan(%superq(attach), &attachc, %str( ));
"%superq(attachnext)"
%end;
)
%end;
;
data _null_;
file mymail;
put &MESSAGE;
run;
filename mymail clear;
%mend email;