Desktop productivity for business analysts and programmers

checking file size and send email

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 318
Accepted Solution

checking file size and send email

Hi Friends - i am not sure if this question appropriate in this pan or not but i wants to raise this issue i have.

We have one file coming from different stream and we use that file to process in SAS. this file has .dat extension. Sometime this file coming in with very small size and i want to know if we have a way in SAS to check file size and send out email to users...

I am using windows 2003/SAS 9.1/EG 4.1

Please help!!!

Thanks!!!


Accepted Solutions
Solution
‎01-21-2014 08:19 PM
Trusted Advisor
Posts: 1,050

Re: checking file size and send email

That's odd, it works for me.

Try this code with a couple of 'put' statements added for logging.

When I run it I see in the log:

rc=0

fid=1

infonum=6

data info;

   length infoname infoval $60;

   drop rc fid infonum i close;

   rc=filename('abc', 'physical-filename');

   put rc =;

   fid=fopen('abc');

   put fid=;

   infonum=foptnum(fid);

   put infonum=;

   do i=1 to infonum;

      infoname=foptname(fid, i);

      infoval=finfo(fid, infoname);

      output;

   end;

   close=fclose(fid);

run;

View solution in original post


All Replies
Grand Advisor
Posts: 17,289

Re: checking file size and send email

You can use system commands to check a file size and you can email users if something is wrong.

Do you have x commands enabled in your environment?

Both of these questions have answers in the forum already.

Super Contributor
Super Contributor
Posts: 318

Re: checking file size and send email

Thanks Reeza!

no, x command is not enable yet. I am in process with admin to make it enable and waiting for same. I am assuming we have to edit objectspawner.bat file with      

    - allowxcmd command.

but what is alternative if admin answer is no. can we still do samething?

Grand Advisor
Posts: 17,289

Re: checking file size and send email

Actually I'm not sure you need x commands, just the pipe.

Try it and let me know Smiley Happy

The following all get filename but the dir statement can be modified to obtain size as well.

Using SAS Macro to pipe a list of filenames from a Windows directory - Stack Overflow

http://www.amadeus.co.uk/sas-technical-services/tips-and-techniques/general/reading-a-file-list-into...

http://support.sas.com/resources/papers/proceedings11/179-2011.pdf

Valued Guide
Posts: 3,206

Re: checking file size and send email

If do not have the xcmd you also do not have the pipe command. That wil bring you no solution.

SAS 9.1.3 is becoming outdated the documentation at the SAS site is starting to dissapear.

You can use wildcards (*?) in filenames and create a list of your needed files in that way. SAS(R) 9.3 Companion for Windows (filename)

You will need  the filevar option of the infile statement. Hmmm not finding any example I did those tricks a long time ago. Should

come up with an example.

Having the real filenames you can try the finfo fucntion (is there in 9.1.3 I believe) SAS(R) 9.3 Companion for Windows    

---->-- ja karman --<-----
Trusted Advisor
Posts: 1,050

Re: checking file size and send email

Try this piece of code from the SAS doc'n....it works for me.

Tom

data info;

   length infoname infoval $60;

   drop rc fid infonum i close;

   rc=filename('abc', 'physical-filename');

   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;

Super Contributor
Super Contributor
Posts: 318

Re: checking file size and send email

Thanks all for your information....

Thanks Tom for posting real code but when i put my values in your code without changing anything i am getting error like,

"invalid do loop control information, either initial or to expression is missing or the by expression is missing, zero or invalid"

Thanks!

Solution
‎01-21-2014 08:19 PM
Trusted Advisor
Posts: 1,050

Re: checking file size and send email

That's odd, it works for me.

Try this code with a couple of 'put' statements added for logging.

When I run it I see in the log:

rc=0

fid=1

infonum=6

data info;

   length infoname infoval $60;

   drop rc fid infonum i close;

   rc=filename('abc', 'physical-filename');

   put rc =;

   fid=fopen('abc');

   put fid=;

   infonum=foptnum(fid);

   put infonum=;

   do i=1 to infonum;

      infoname=foptname(fid, i);

      infoval=finfo(fid, infoname);

      output;

   end;

   close=fclose(fid);

run;

Super Contributor
Super Contributor
Posts: 318

Re: checking file size and send email

my file name is AB.WOOLAWSON.USWOO.DAT and this would be around .5 gb. sometimes it come with .2 gb which is much smaller and wants to create email alerts to users....

Thanks!

New Contributor
Posts: 4

Re: checking file size and send email

You could try using a filename statement to point to the file you want to check, then use the SASHELP.VEXTFL dictionary table to extract the size information;

filename myfile 'D:\myfile.dat';

data _null_;

  set sashelp.vextfl;

  if fileref = "MYFILE" then do;

  size_in_gb = (filesize / (1024**3));

  put size_in_gb=;

  end;

run;

Super Contributor
Super Contributor
Posts: 318

Re: checking file size and send email

Thanks Tom and HJD24.

meanwhile i have used different approch,

i used proc export to get file in SAS and then used %sysfunc (open)/attrn/close options to get record and then email logic to send an email...this works fine for me...

Thanks!

Super Contributor
Super Contributor
Posts: 318

Re: checking file size and send email

- HJD24 - in your code - filesize variable is uninitialized.

Thanks!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 789 views
  • 0 likes
  • 5 in conversation