BookmarkSubscribeRSS Feed
Yonichen73
Calcite | Level 5

hey everybody,

 

I would like to send an email with multiple files  and I am trying to do that with "macro"

the email should be send according to the time of the year.

for example I have some files that should be send once in a quarter and other file once in a half year;

 

this is my code:

 

data _null_;
dt=intnx('month',date(),0,'S');
ind=month(dt);
if ind in (3,5,9,11) then the_run='Dual';
if ind in(4,10) then the_run='Quarterly';
if ind in (1,7) then the_run='hdq';
call symput('the_run',the_run);
run;

%put &the_run.;


%macro emailm;
%if "&the_run."="hdq" %then %do; 
filename TestR email to = ("jonathan.chen@poalim.co.il") 
SUBJECT=" %SYSFUNC(date(), YYMMdd10.)צ'ק ליסט דו חודשי לתאריך "
type='text/html'
attach=("&path\SHOTEF_MNG_SNIF_MNG_PRATIT_&the_month&format" content_type="application/xlsx"
"&path\CHECK_LIST_CONNECT_&the_month&format" content_type="application/xlsx") 
encoding='whebrew';

data _null_;
file TestR;
run;
%end;
%else %if "&the_run."="Quarterly" %then %do;
/*שליחת קבצים של הרצה רבעונית*/
filename TestR email to = ("jonathan.chen@poalim.co.il")
cc= ("jonathan.chen@poalim.co.il")
SUBJECT=" %SYSFUNC(date(), YYMMdd10.)צ'ק ליסט רבעוני לתאריך "
type='text/html'
attach=("&path\CHECK_LIST_PLAT_&the_month&format" content_type="application/xlsx"
"&path\CHECK_LIST_CONNECT_&the_month&format" content_type="application/xlsx") 
encoding='whebrew';

data _null_;
file TestR;
run;
%end;
%else %if "&the_run."="Dual" %then %do;
/*שליחת קבצים של הרצה חצי שנתית*/
filename TestR email to = ("jonathan.chen@poalim.co.il") 
SUBJECT=" %SYSFUNC(date(), YYMMdd10.)צ'ק ליסט חצי שנתי לתאריך "
type='text/html'
attach=("&path\SHOTEF_CONS_MNG_AREA_MNG_PRATIT_&the_month&format" content_type="application/xlsx") 
encoding='whebrew';

data _null_;
file TestR;
run;
%end;

%mend;
%emailm;

 

 

 

/**/

 

and this is what I get in the log:

 

 

 

1 The SAS System 11:06 Sunday, January 6, 2019

1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='Program';
4 %LET _CLIENTPROCESSFLOWNAME='Email_Send';
5 %LET _CLIENTPROJECTPATH='\\nasdepartments\DHC\General\HQ\מטה\צוות אנליזה\מערכת בקרות והדרכות\אכיפה מנהלית-
5 ! CHECK_LIST\צ''ק ליסט 2019\צק ליסט_V17_1.egp';
6 %LET _CLIENTPROJECTNAME='צק ליסט_V17_1.egp';
7 %LET _SASPROGRAMFILE=;
8
9 ODS _ALL_ CLOSE;
10 OPTIONS DEV=ACTIVEX;
11 GOPTIONS XPIXELS=0 YPIXELS=0;
12 FILENAME EGSR TEMP;
13 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
14 STYLE=HtmlBlue
15 STYLESHEET=(URL="file:///C:/Program%20Files%20(x86)/SASHome/x86/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
16 NOGTITLE
17 NOGFOOTNOTE
18 GPATH=&sasworklocation
19 ENCODING=UTF8
20 options(rolap="on")
21 ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
22
23 GOPTIONS ACCESSIBLE;
24
25
26 %macro emailm;
27 %if "&the_run."="hdq" %then %do;
28 filename TestR email to = ("jonathan.chen@poalim.co.il") /*כתובת מייל תפוצה ייעודית לתהליך*/
29 SUBJECT=" %SYSFUNC(date(), YYMMdd10.)צ'ק ליסט דו חודשי לתאריך "
30 type='text/html'
31 attach=("&path\SHOTEF_MNG_SNIF_MNG_PRATIT_&the_month&format" content_type="application/xlsx"
32 "&path\CHECK_LIST_CONNECT_&the_month&format" content_type="application/xlsx")
33 encoding='whebrew';
34
35 data _null_;
36 file TestR;
37 run;
38 %end;
39 %else %if "&the_run."="Quarterly" %then %do;
40 /*שליחת קבצים של הרצה רבעונית*/
41 filename TestR email to = ("jonathan.chen@poalim.co.il")
42 cc= ("jonathan.chen@poalim.co.il")/*כתובת מייל תפוצה ייעודית לתהליך*/
43 SUBJECT=" %SYSFUNC(date(), YYMMdd10.)צ'ק ליסט רבעוני לתאריך "
44 type='text/html'
45 attach=("&path\CHECK_LIST_PLAT_&the_month&format" content_type="application/xlsx"
46 "&path\CHECK_LIST_CONNECT_&the_month&format" content_type="application/xlsx")
47 encoding='whebrew';
48
49 data _null_;
50 file TestR;
51 run;
52 %end;
53 %else %if "&the_run."="Dual" %then %do;
54 /*שליחת קבצים של הרצה חצי שנתית*/
55 filename TestR email to = ("jonathan.chen@poalim.co.il") /*כתובת מייל תפוצה ייעודית לתהליך*/
56 SUBJECT=" %SYSFUNC(date(), YYMMdd10.)צ'ק ליסט חצי שנתי לתאריך "
2 The SAS System 11:06 Sunday, January 6, 2019

57 type='text/html'
58 attach=("&path\SHOTEF_CONS_MNG_AREA_MNG_PRATIT_&the_month&format" content_type="application/xlsx")
59 encoding='whebrew';
60
61 data _null_;
62 file TestR;
63 run;
64 %end;
65
66 %mend;
67 %emailm;
68
69 GOPTIONS NOACCESSIBLE;
70 %LET _CLIENTTASKLABEL=;
71 %LET _CLIENTPROCESSFLOWNAME=;
72 %LET _CLIENTPROJECTPATH=;
73 %LET _CLIENTPROJECTNAME=;
74 %LET _SASPROGRAMFILE=;
75
76 ;*';*";*/;quit;run;
77 ODS _ALL_ CLOSE;
78
79
80 QUIT; RUN;
81

 

 

thanks in advance

4 REPLIES 4
Yonichen73
Calcite | Level 5

hi.

 

thanks for the quick answer.

 

the_run macro gets:'hdq' because the month is 1 (January)  and I was checking that with %put &the_run.;
and then I got: hdq

Kurt_Bremser
Super User

Your log does not show the %put, so it might have run in a different context.

Your data _null_ that sets the macro variable is faulty; see Maxim 47 (Quarterly will be shortened to Quar).

Additionally, use call symputx (which removes trailing blanks from values), or omit the double quotes in the %if conditions. In macro language, "hdt" is different from "hdt ".

Yonichen73
Calcite | Level 5

It works.

 

thank you very much :]

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 990 views
  • 0 likes
  • 2 in conversation