/*** TIP 00386 ***/
How to determine if an external file is empty or not

solution #1
By Charles Patridge

%let external = c:\download\trace_empty.txt; /*** check an empty file ***/
***%let external = c:\download\trace_noexist.txt;  /*** check if file does not exist ***/
***%let external = c:\download\trace_nonempty.txt; /*** check if file is not empty ***/
 

options noxwait; 
 
 /*** this will provide size in bytes of the file - if it exists ***/ 
%macro filesize( _extfile_ ); 
 %global _size_ ; 
 %if %sysfunc( fileexist( &_extfile_ ) ) %then %do; 
   x dir &_extfile_ >c:\dir.lis ; /*** WINDOWS syntax of Directory Command ***/ 
   data _null_; 
   length record $ 200. ; 
   infile "c:\dir.lis" length=len missover/*** file attributes on 6th record for Windows 2000***/; 
   input record $varying. len ; 
   if index(record, '/') > 0 then do; /*** pick up a date record ***/ 
     size = scan( record, 3, " " ); /*** 3rd word using blanks as delimiter gives size ***/ 
     call symput('_size_', Left(compress(size)) ); 
   end; 
   run; 
 %end; 
 %else %do; 
   %let _size_ = File Does Not Exist; 
 %end; 
%mend filesize; 

 
%filesize( &external ); 
 
%put "&_size_"; 

A much simpler solution by Paul Dorfman %let fname = c:\download\trace_empty.txt ; %let fname = c:\download\trace.htm ; data _null_ ; infile "&fname" end = empty ; put empty= ; run ; /*** end of tip 00386 ***/