BookmarkSubscribeRSS Feed
vomer
Obsidian | Level 7

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!

10 REPLIES 10
LinusH
Tourmaline | Level 20

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.

Data never sleeps
Tom
Super User Tom
Super User

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;

vomer
Obsidian | Level 7

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?

FriedEgg
SAS Employee

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

vomer
Obsidian | Level 7

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?

FriedEgg
SAS Employee

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.

vomer
Obsidian | Level 7

Unfortunately the log has no errors. Looks like a formatting issue.

FriedEgg
SAS Employee

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.

ArtC
Rhodochrosite | Level 12

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;

vomer
Obsidian | Level 7

Thanks Art, I will try this.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 10 replies
  • 1282 views
  • 6 likes
  • 5 in conversation