Hi Guys,
I use this code right now to send out an alert email once the code is done running:
filename outmail email "abc@abc.com"
subject="SAS"
cc="abc@aaa.com"
;
data _null_;
file outmail;
put 'Hello';
put;
put 'The weekly code has completed.';
put;
run;
Is is possible for me to somehow include the file size and file info in this email? Something along the lines of : http://support.sas.com/kb/38/267.html
Please provide the code if possible! Thanks!
File info of what file?
If it's an external file, just adjust and merge the code in the example with your own, and include the desired values in the put statements.
Sure. I have done it many times. You first need to gather the information you want to present. Perhaps you want to send information on the datasets you generated?
proc contents data=out._all_ noprint out=contents; run;
data _null_;
file outmail;
if _n_=1 then put 'The job completed. Dataset sizes are below.';
set contents;
by memname;
if first.memname then put memname= nobs= ;
run;
Actually, I am basically looking to put information on 1 file, foe example:
C:\Temp\data.sas
At minimum, I want to put the file size in the email (in MB if possible). An output like this would be even better!:
Filename C:\Temp\data.sas
File Size (MB) 30
Last Modified 05May2009:10:44:23
Create Time 04May2009:17:04:22
Would there be a way to do this?
filename eml email to="abc@def.com" subject="From SAS" content_type='text/html';
ods html file=eml style=minimal;
data info;
length infoname infoval $60;
drop rc fid infonum i close;
rc=filename("abc","/path/to/file");
fid=fopen("abc");
infonum=foptnum(fid);
do i=1 to infonum;
infoname=foptname(fid,i);
infoval=finfo(fid,infoname);
output;
end;
close=fclose(fid);
run;
ods text='Hello,';
ods text='The weekly code has completed.';
ods text=' ';
option nocenter nodate;
proc print data=info noobs;
title1 "Attributes obtained for a file";
run;
Hello,
The weekly code has completed.
Attributes obtained for a file |
Filename | /path/to/file |
Owner Name | abc |
Group Name | def |
Access Permission | rw-r--r-- |
Last Modified | Tue May 11 15:55:20 2010 |
File Size (bytes) | 124 |
Thanks! that seems to work but when I get the email it is all HTML code and I do not see the output like you have included here. Would you happen to know why and how I can fix it?
Provide a log or something or I cannot really provide any additional help or information for what specific issue you are having. If you copied the example as provided then you should see results as provided in email.
Unfortunately the log has no errors. Looks like a formatting issue.
You issue is too vague and not useful to perform any meaningful diagnosis. Move ahead with the suggestion from Art. The easiest explanation would be that your email host/client does not accept HTML formatted emails.
Your e-mail settings may prevent you from receiving HTML. As an alternative you could have the file as an attachment. Here it is PDF - just to be different. Also I have left the HELLO as part of the email. Leaving it as ODS TEXT as FriedEgg has it will include it in the attached file. A final DATA _NULL_ step is then used to generate the e-mail.
filename eml email to=sam@caloxy.com
subject="From SAS"
content_type='text/html'
attach="c:\temp\results.pdf";
ods pdf file="c:\temp\results.pdf" style=minimal;
data info;
length infoname infoval $60;
drop rc fid infonum i close;
rc=filename("abc","c:\temp\testinc.sas");
fid=fopen("abc");
infonum=foptnum(fid);
do i=1 to infonum;
infoname=foptname(fid,i);
infoval=finfo(fid,infoname);
output;
end;
close=fclose(fid);
run;
ods text=' ';
option nocenter nodate;
proc print data=info noobs;
title1 "Attributes obtained for a file";
run;
ods pdf close;
data _null_;
file eml;
put 'Hello,';
put 'The weekly code has completed.';
run;
Thanks Art, I will try this.
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!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.