/*** TIP 00381 **/
loading 500 flat files in a loop

 I have axtract a single column from 500 files and put
 them in one file. The names of the file are a1.txt
 through a500.txt. After loading I need to check
 whether the number of rows are greater than 3000. If
 it is less then the file should be ignored. If it is
 more than 3000 then the first 3000 rows should be read
 and a column needs to extracted from the file. Is
 there anyway I can read them in a loop and extract the
 columns. 

Solution #1 
Gerhard Hellriegel
Email: ghellrieg@_NOSPAM_T-ONLINE.DE

That sounds rather complex.
Without knowing much about the structure of your flat files, I assume that
they have no special structure, like a DB or VSAM. That would be the only
chance to say anything about the files about rows and columns. So I see
only one possibility to get the information about your more or less than
3000 records: you have to read them all!
First step I see:
- fetch all names of the files. If they are really a1 - a500 that is easy.
- use a macro to put your logic in. Something like:

%macro a;
  %do i=1 %to 500;
  %let n=0;
  data a;
     infile "a&i..txt" ...options ..;
     input .....;
     call symput("n",_n_);
  run;
  %if &n ge 3000 %then %do;
    proc append base=all new=a force; run;
  %end;
  data a; stop; run;
  %end;
%mend;

%a;

After that you should have all what you want in dataset ALL.

Solution #2 Richard A. DeVenezia Email: radevenz@_NOSPAM_IX.NETCOM.COM Presuming the file structure is consistent across all the files. You can either A. buffer reading the first 3000, if 3000 never reached you wouldn't 'unbuffer' them [not shown] or B. read everything and ignore data from files with LT 3000 records. data bunch; do i = 1 to 500; filename = 'a' || trim (put (i,4.-L)) || '.txt'; infile filevar=filename end=eof; do until (eof) input myvar; output; end; end; run; proc sql; create table bunch2 as select * from bunch where filename in (select filename from bunch group by filename having count(*) gt 3000); quit;
Solution #3 Droogendyk, Harry Email: Harry.Droogendyk@_NOSPAM_CIBC.COM If Santosh is fortunate enough to be running on UNIX, the 'wc' verb can be used to count lines. Filenames with >= 3000 lines are pumped out to a SAS dataset. The next step reads the SAS dataset and uses the filevar option on the infile to read each file in turn. filename count pipe 'wc /unix/directory/*.txt'; data files ( keep = file ); infile count end=done missover; input lines dummy1 dummy2 file : $100.; if lines LT 3000 or done then delete; /* Last line is 'total', do not want it */ run; data all; do until(done); set files end=done; eof = 0; infile stuff filevar=file end = eof ; do until(eof); input column $; output; end; end; run;
/*** end of tip 00381 ***/