BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_Question
Quartz | Level 8

Hello my friends, 

 

Can someone analyse my code and tell me why SAS doens't mail on monday? This is the code: 

 

/*
rest of code...
*/


%Macro exporteer;
proc export data=work.verschillend 
				outfile="&Uitvoer.\Volher_Rundate[&dat1.].txt" 
				dbms=tab replace;
	*putnames=no;
run;
%Mend exporteer;


%MACRO mailen;
%let adres = "someone@sas.nl" , "other@sas.nl"; /* I use fake email addresses here, but in real code the real email is used! */

FILENAME mail0 EMAIL  
	To=(&adres)
	SUBJECT="Some subject" 
	from   ="NOREPLY <NOREPLY@sas.nl>"        
	Type   ="text/plain" 
	Attach =("&Uitvoer.\Volher_Rundate[&dat1.].txt") 
	Replyto="ME <me@sas.nl>";

Data _null_;
	file mail0;
	put "some text"; 
	put " ";
	put " ";
	put " ";
	put " ";
	put "Some more text";
	put "Final text";
run;
%MEND mailen;

/*Mailen van txt bestand - alleen op maandag!*/
%MACRO mail_als;
	%If %SYSFUNC(WEEKDAY(%SYSFUNC(TODAY()))) = 2 %then /* 2 = monday = mailing day */
		%do;
			%exporteer; /*this works!*/
			
			%mailen; /*this doesn't work - only if put outside macro, but in macro it won't work?? why?? */
		%END ;
%MEND mail_als;

%mail_als;

And this is what is should do

 

It should export a txt file only on each monday (which works well) and then email this exported file (also only echa monday). But this doensn't work? It doesn't email it? 

 

What i did to solve already

I put the macro code for emailing outside the macro, and then it emails the file. But i don't want that, because then the program will email it everytime the code runs. That is not what i want. 

 

Hope someone can solve it for me. 

TiA! 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Keep your original code that failed, for later reference.

Take this code that works, and expand it step-by-step; test with everything you want it to do.

If at some point it stops working, you have a clue. If you come through without problems, compare your preserved original code with the new one.

 

I still think the asterisk in your log (indicating a comment statement) was a remnant of testing, and you missed to submit a changed macro definition. (submit: mark the macro code, and select "Run Selection" from the menu)

View solution in original post

17 REPLIES 17
Kurt_Bremser
Super User

Please post the log of the macro call; use

options mprint mlogic symbolgen;

to activate all macro debugging helpers.

Please use the {i} button for posting the log.

SAS_Question
Quartz | Level 8

Hi Kurt,

 

This is the macro log output: 

 

MLOGIC(MAILEN):  Beginning execution.
MLOGIC(MAILEN):  %LET (variable name is adres)
MLOGIC(MAILEN):  %LET (variable name is adres)
MPRINT(MAILEN):   * FILENAME mail0 EMAIL To=(&adres) SUBJECT="Some subject" from ="NOREPLY <NOREPLY@sas.nl>" Type ="text/plain" Attach
=("&Uitvoer.\VolHer_Rundate[&dat1.].txt") Replyto="ME <me@sas.nl>";
MPRINT(MAILEN):   Data _null_;
MPRINT(MAILEN):   file mail0;
MPRINT(MAILEN):   put "Some text";
MPRINT(MAILEN):   put " ";
MPRINT(MAILEN):   put " ";
MPRINT(MAILEN):   put " ";
MPRINT(MAILEN):   put " ";
MPRINT(MAILEN):   put "Some more text.";
MPRINT(MAILEN):   put "Final text.";
MPRINT(MAILEN):   run;

NOTE: The file MAIL0 is:
      Filename=\\Client\J$\some\dir\on\network\mail0.dat,
      RECFM=V,LRECL=32767,File Size (bytes)=0,
      Last Modified=31 juli 2019 10:18:04 uur,
      Create Time=31 juli 2019 10:18:04 uur

NOTE: 7 records were written to the file MAIL0.
      The minimum record length was 1.
      The maximum record length was 79.
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.01 seconds

MLOGIC(MAILEN):  Ending execution.
MPRINT(MAIL_ALS):  ;
MLOGIC(MAIL_ALS):  Ending execution.

 

Still no idea why this doesn't work in a macro... 😞 

 

 

Kurt_Bremser
Super User

See this:

MPRINT(MAILEN):   * FILENAME mail0 EMAIL To=(&adres) SUBJECT="Some subject" from ="NOREPLY <NOREPLY@sas.nl>" Type ="text/plain" Attach
=("&Uitvoer.\VolHer_Rundate[&dat1.].txt") Replyto="ME <me@sas.nl>";

Note the asterisk. The filename statement is commented out, so a previous filename with a physical filename (from testing?) is active and used:

NOTE: The file MAIL0 is:
      Filename=\\Client\J$\some\dir\on\network\mail0.dat,
SAS_Question
Quartz | Level 8

I deleted the mail0(.dat) file on the network disk/map but still SAS doesn't email the file to me? 

I still don't understand this error... sorry. 

 

 

 

Kurt_Bremser
Super User

@SAS_Question wrote:

I deleted the mail0(.dat) file on the network disk/map but still SAS doesn't email the file to me? 

I still don't understand this error... sorry. 

 

 

 


That won't help. You have to un-comment the filename mail statement.

SAS_Question
Quartz | Level 8

But I didn't commented it out in the code? See the picture: 

 

mail uncommented.png

Kurt_Bremser
Super User

PS what you see in your code doesn't have to be what SAS has stored as a compiled macro. After every change to macro code, make sure that the macro definition is actually submitted.

If in doubt, terminate your SAS session, start a new one, and submit the macro definition and the macro call in immediate succession.

SAS_Question
Quartz | Level 8

Thanks for your efforts and time, Kurt.

After every change to macro code, make sure that the macro definition is actually submitted.

 

What do you mean by this? 

And how do I make sure it is submitted? 

 

What I Already did now

Already closed my sas-program and rerun it. But no luck.. still no email 

Closed it again. Changed the filename in the macro code form mail0 to mail1... rerun it...

But still no luck here.. sorry. 

 

Kurt_Bremser
Super User

Start a new SAS session.

Run this code (and NOTHING else!); only replace XXXX with your email:

%let adres = "XXXX";

%Macro exporteer;
%put exporteer running;
%Mend exporteer;


%MACRO mailen;


FILENAME mail0 EMAIL  
	To=(&adres)
	SUBJECT="Some subject" 
	from   ="NOREPLY <NOREPLY@sas.nl>"        
	Type   ="text/plain" 
;

Data _null_;
	file mail0;
	put "some text"; 
	put " ";
	put " ";
	put " ";
	put " ";
	put "Some more text";
	put "Final text";
run;
%MEND mailen;

%MACRO mail_als;
	%If %SYSFUNC(WEEKDAY(%SYSFUNC(TODAY()))) = 4 %then 
		%do;
			%exporteer;			
			%mailen;
		%END ;
%MEND mail_als;

options mprint mlogic symbolgen;

%mail_als;

My log from this code:

24         %let adres = "XXXX";
25         
26         %Macro exporteer;
27         %put exporteer running;
28         %Mend exporteer;
29         
30         
31         %MACRO mailen;
32         
33         
34         FILENAME mail0 EMAIL
35         	To=(&adres)
36         	SUBJECT="Some subject"
37         	from   ="NOREPLY <NOREPLY@sas.nl>"
38         	Type   ="text/plain"
39         ;
40         
41         Data _null_;
42         	file mail0;
43         	put "some text";
44         	put " ";
45         	put " ";
46         	put " ";
47         	put " ";
48         	put "Some more text";
49         	put "Final text";
50         run;
51         %MEND mailen;
52         
53         %MACRO mail_als;
54         	%If %SYSFUNC(WEEKDAY(%SYSFUNC(TODAY()))) = 4 %then
55         		%do;
56         			%exporteer;			
57         			%mailen;
2                                                          Das SAS System                             14:00 Wednesday, July 31, 2019

58         		%END ;
59         %MEND mail_als;
60         
61         options mprint mlogic symbolgen;
62         
63         %mail_als;
MLOGIC(MAIL_ALS):  Ausführung beginnt.
MLOGIC(MAIL_ALS):  %IF-Bedingung %SYSFUNC(WEEKDAY(%SYSFUNC(TODAY()))) = 4 ist TRUE
MLOGIC(EXPORTEER):  Ausführung beginnt.
MLOGIC(EXPORTEER):  %PUT exporteer running
exporteer running
MLOGIC(EXPORTEER):  Ausführung wird beendet.
MPRINT(MAIL_ALS):  ;
MLOGIC(MAILEN):  Ausführung beginnt.
SYMBOLGEN:  Makrovariable ADRES wird in "XXXX" aufgelöst
MPRINT(MAILEN):   FILENAME mail0 EMAIL To=("XXXX") SUBJECT="Some subject" from ="NOREPLY <NOREPLY@sas.nl>" Type 
="text/plain" ;
MPRINT(MAILEN):   Data _null_;
MPRINT(MAILEN):   file mail0;
MPRINT(MAILEN):   put "some text";
MPRINT(MAILEN):   put " ";
MPRINT(MAILEN):   put " ";
MPRINT(MAILEN):   put " ";
MPRINT(MAILEN):   put " ";
MPRINT(MAILEN):   put "Some more text";
MPRINT(MAILEN):   put "Final text";
MPRINT(MAILEN):   run;

NOTE: The file MAIL0 is:
      E-Mail-Zugriffskomponente

Nachricht gesendet
      An:          "XXXX"
      Cc:          
      Bcc:         
      Betreff:     Some subject
      Anhänge: 
NOTE: 7 records were written to the file MAIL0.
      The minimum record length was 1.
      The maximum record length was 14.
NOTE: DATA statement used (Total process time):
      real time           0.06 seconds
      cpu time            0.00 seconds
      

MLOGIC(MAILEN):  Ausführung wird beendet.
MPRINT(MAIL_ALS):  ;
MLOGIC(MAIL_ALS):  Ausführung wird beendet.

The email arrived as wanted.

SAS_Question
Quartz | Level 8

Thank you Kurt. I tried the code like this, (added the attachment too - a txt file): 

 

%let adres = "mymail@somehost.nl";

%Macro exporteer;
%put exporteer running;
%Mend exporteer;


%MACRO mailen;


FILENAME mail0 EMAIL  
	To=(&adres)
	SUBJECT="Some subject" 
	from   ="NOREPLY <NOREPLY@sas.nl>"        
	Type   ="text/plain" 
	Attach =("J:\some\dir\to\the\exported\file.txt") 
;

Data _null_;
	file mail0;
	put "some text"; 
	put " ";
	put " ";
	put " ";
	put " ";
	put "Some more text";
	put "Final text";
run;
%MEND mailen;

%MACRO mail_als;
	%If %SYSFUNC(WEEKDAY(%SYSFUNC(TODAY()))) = 4 %then 
		%do;
			%exporteer;			
			%mailen;
		%END ;
%MEND mail_als;

options mprint mlogic symbolgen;

%mail_als;

And this works?!! 

 

But I still don't know why this works and the orginal code doesn't work?

What is the difference then? 
Will have to start all over then... if no one knows why. I really don't understand this one.

 

 

Kurt_Bremser
Super User

Keep your original code that failed, for later reference.

Take this code that works, and expand it step-by-step; test with everything you want it to do.

If at some point it stops working, you have a clue. If you come through without problems, compare your preserved original code with the new one.

 

I still think the asterisk in your log (indicating a comment statement) was a remnant of testing, and you missed to submit a changed macro definition. (submit: mark the macro code, and select "Run Selection" from the menu)

SAS_Question
Quartz | Level 8

Thank you Kurt, will try this out next week. This week I'm very busy yet. 

As soon as I tried it I will let you know if it works. Thanks so far and have a nice day!

 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 17 replies
  • 1913 views
  • 3 likes
  • 2 in conversation