DATA Step, Macro, Functions and more

macro to send email with option ATTACH not fill in

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 111
Accepted Solution

macro to send email with option ATTACH not fill in

hello,

 

%macro mc_email (to=, from=, cc=, subject=, sender=, texte=, expediteur=, attach=) ;

DATA _null_ ;
slept= sleep(120);
run;

data _null_;
filename mail email to=(&to.) from=&from.
cc=(&cc.)
subject=&subject.
sender=&sender.
ATTACH= (&attach.)
;

file mail;
put 'Bonjour,' ; 
put ' ' ;
put "&texte." ; 
put ' ' ;
put 'Cordialement,' ;
put ' ' ;
put "&expediteur." ;
run;

%mend mc_email ;


%mc_email(  to = &mv_email_destinataire_list, 
		                from = "Mr Nasser",        
		                  cc = &mv_email_copie_list,                    
		             subject = "Execution ra_retention : OK",
		              sender = "lauch_ra_retention.sas",
		               texte = Le programme s est déroulé sans erreur,
		          expediteur = Mr Nasser ,
					attach= );

 

I call this macro by specifiying a file in the "attach" option--> it works
I call this macro by NOT specifiying a file in the "attach" option--> it DOES NOT works.

What could I do to make this macro working for both options ("attach" fill in or not) ?

 

thanks a lot in advance for your help


Accepted Solutions
Solution
‎04-05-2018 07:42 AM
Super User
Posts: 9,559

Re: macro to send email with option ATTACH not fill in

Posted in reply to Nasser_alfea

You can omit the double quotes:

%if &attach. ne  %then %do;
ATTACH= (&attach.)
%end;

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Super User
Posts: 9,559

Re: macro to send email with option ATTACH not fill in

Posted in reply to Nasser_alfea

Use a condition:

data _null_;
filename mail email to=(&to.) from=&from.
cc=(&cc.)
subject=&subject.
sender=&sender.
%if "&attach." ne "" %then %do;
ATTACH= (&attach.)
%end;
;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 111

Re: macro to send email with option ATTACH not fill in

Posted in reply to KurtBremser

Hello Kurt and thanks for your quick repsonse.

I test your solution.

without specifiied file, it works. but by specifying a file like

attach= "/home/ldap/mellouna/lance_prog_cdgr.log" I got an error message

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:

"&attach." ne ""

 

Solution
‎04-05-2018 07:42 AM
Super User
Posts: 9,559

Re: macro to send email with option ATTACH not fill in

Posted in reply to Nasser_alfea

You can omit the double quotes:

%if &attach. ne  %then %do;
ATTACH= (&attach.)
%end;

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 111

Re: macro to send email with option ATTACH not fill in

Posted in reply to KurtBremser
It works perfectly thanks !
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 81 views
  • 0 likes
  • 2 in conversation