That code is just trying to find the number of fields on the FIRST line of the file. That could be done more simply with:
data _null;
call symputx('ncol',ncol);
infile "&dir.test.csv" obs=1;
ncol + countw(_infile_,',','mq');
run;
Which will return 0 for a file with no lines.
I thought you wanted to check if the file consistently had the same number of fields on every line. To do that you need to read the whole file.
data _null;
if eof then do;
call symputx('nobs',_n_-1);
call symputx('ncol',ncol);
call symputx('nbad',nbad);
end;
infile "&dir.test.csv" end=eof;
if _n_=1 then ncol = countw(_infile_,',','mq');
else nbad + (ncol ne countw(_infile_,',','mq'));
retain ncol nbad 0;
run;
... View more