BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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!!!

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

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

11 REPLIES 11
Reeza
Super User

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.

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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?

Reeza
Super User

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

jakarman
Barite | Level 11

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 --<-----
TomKari
Onyx | Level 15

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;

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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!

TomKari
Onyx | Level 15

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;

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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!

HJD24
Calcite | Level 5

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;

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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!

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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

Thanks!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 11 replies
  • 3051 views
  • 0 likes
  • 5 in conversation