0
votes

I'm trying to import series of CSV files with a macro that loops thru all the files in the given folder.But, there are some empty CSV files in the folder which I would like to exclude from the loop. Is there any way in SAS to find CSV file size ?

PROC IMPORT OUT=&output
            DATAFILE= "&input"
            DBMS=CSV REPLACE;
     GETNAMES=YES;
     DATAROW=2;
        *GUESSINGROWS=32000;
RUN;

Thanks, Sam.

3
Presumably by empty you mean no header row as well as no data?user667489
@user667489 : Yeah....no data as well as no header....SAS_learner

3 Answers

1
votes

Here's away to do it in a datastep:

filename fileref 'c:\date.tmp';
data a;
infile fileref truncover;
fid=fopen('fileref');
Bytes=finfo(fid,'File Size (bytes)');                                                                                  
crdate=finfo(fid,'Create Time');
moddate=finfo(fid,'Last Modified');
input var1 $20.;
run;
0
votes
%macro FileAttribs(filename);
  %local rc fid fidc Bytes;
   %let rc=%sysfunc(filename(onefile,&filename));
   %let fid=%sysfunc(fopen(&onefile));
   %let Bytes=%sysfunc(finfo(&fid,File Size (bytes)));
        %if &Bytes >0 %then %do;
                %put #####Size is > 0#####;
        %end;
        %else %do;
                %put #####Size is < 0#####;
        %end;
   %let fidc=%sysfunc(fclose(&fid));
   %let rc=%sysfunc(filename(onefile));
    %put NOTE: File size of &filename is &Bytes bytes;
%mend FileAttribs;
0
votes

and here's another way to do it:

 %let filename =c:\date.tmp;                                                                                                       
 %let rc=%sysfunc(filename(onefile,&filename)); 

 %let fid=%sysfunc(fopen(&onefile));                                                                                                  
 %let Bytes=%sysfunc(finfo(&fid,File Size (bytes)));                           
 %let fidc=%sysfunc(fclose(&fid));                                                                                                    

 %put NOTE: File size of &filename is &Bytes bytes;