Help using Base SAS procedures

Put File Size/Details in SAS Auto Email

Reply
Frequent Contributor
Posts: 117

Put File Size/Details in SAS Auto Email

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!

Super User
Posts: 5,435

Re: Put File Size/Details in SAS Auto Email

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
Super User
Super User
Posts: 7,074

Re: Put File Size/Details in SAS Auto Email

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;

Frequent Contributor
Posts: 117

Re: Put File Size/Details in SAS Auto Email

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?

Trusted Advisor
Posts: 1,301

Re: Put File Size/Details in SAS Auto Email

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

Frequent Contributor
Posts: 117

Re: Put File Size/Details in SAS Auto Email

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?

Trusted Advisor
Posts: 1,301

Re: Put File Size/Details in SAS Auto Email

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.

Frequent Contributor
Posts: 117

Re: Put File Size/Details in SAS Auto Email

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

Trusted Advisor
Posts: 1,301

Re: Put File Size/Details in SAS Auto Email

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.

Valued Guide
Posts: 634

Re: Put File Size/Details in SAS Auto Email

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;

Frequent Contributor
Posts: 117

Re: Put File Size/Details in SAS Auto Email

Thanks Art, I will try this.

Ask a Question
Discussion stats
  • 10 replies
  • 362 views
  • 6 likes
  • 5 in conversation