BookmarkSubscribeRSS Feed
Gpp
Fluorite | Level 6 Gpp
Fluorite | Level 6

Hi all,

 

I got a report that need input file from user, I wish to automate it so if user had put the file in the path then run the report_code.sas , else send out an email to remind them.

 

What I plan to do is ,build a new control code, by using Macro to check fileexist , if yes , then run %include “&path./report_code.sas” , if no then send a auto email.

 

I just notice that %include in a macro will caused an error. Even though the %include was successfully run. Any other method can recommend to me to avoid the error due to %include in a macro ?

 

Thanks in advance !

5 REPLIES 5
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

I hope that when you get your logic to preform as expected that you don't spam the reports generator with the email, please send me the file """ every 5 minutes.  People at work are trying to do the same thing not allowing enough sleep time.

 

Patrick
Opal | Level 21

@Gpp 

"I just notice that %include in a macro will caused an error."

You can do what you want if your syntax is correct. We can't help much though if you don't share your not yet working code with us; plus the error in the log or a description of the undesired behavior and how it should behave.

Gpp
Fluorite | Level 6 Gpp
Fluorite | Level 6

hi Patrick, yes, I found my error and it' working ! thanks for the comment 😃

Amir
PROC Star

It's good that you found your solution, it would be even better if you shared it with the community so that others may also benefit.

 

Amir.

Gpp
Fluorite | Level 6 Gpp
Fluorite | Level 6

Sure!

 

%macro findfile;
	%if %sysfunc(fileexist("&sharepath./INPUT/&filename..xlsx")) %then %do;
		%include "&path./CODE/LI_main.sas";		
	%end;
	
	%else %do;
	FILENAME TESTMAIL EMAIL TO = (&mailto.) 
							CC = (&mailcc.) 
							FROM=&mailfrom.			
	SUBJECT = "Weekly Report (Automated Message)";			
	DATA _NULL_;			
    	FILE TESTMAIL;			
    	PUT "Hi &username.,";			
    	PUT " ";			
    	PUT "No input file in &sharepath./INPUT/&filename..xlsx ";			
    	PUT "Extraction is aborted.";	
    	PUT " ";			
    	PUT "Thanks and regards,";			
    	PUT "xx";			
	RUN;
	
	%end;
	
%mend;
%findfile;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1570 views
  • 2 likes
  • 4 in conversation