在SAS中导入空CSV文件

时间:2015-07-14 14:52:56

标签: sas

我尝试使用宏来导入一系列CSV文件,这些宏循环通过给定文件夹中的所有文件。但是,文件夹中有一些空的CSV文件,我想从循环中排除。 SAS中有没有找到CSV文件大小的方法?

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

3 个答案:

答案 0 :(得分:1)

这是在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;

答案 1 :(得分:0)

%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;

答案 2 :(得分:0)

这是另一种方法:

 %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;