/* Changes are indicated with an arrow. */ data _null_; file '~/samp157/extfile1.txt'; /* <------------------ */ put "05JAN2001 6 W12301 1.59 9.54"; put "12JAN2001 3 P01219 2.99 8.97"; run; /* Create external file EXTFILE2 */ data _null_; file '~/samp157/extfile2.txt'; /* <------------------ */ put "02FEB2001 1 P01219 2.99 2.99"; put "05FEB2001 3 A00901 1.99 5.97"; put "07FEB2001 2 C21135 3.00 6.00"; run; /* Create the external file EXTFILE3 */ data _null_; file '~/samp157/extfile3.txt'; /* <------------------ */ put "06MAR2001 4 A00101 3.59 14.36"; put "12MAR2001 2 P01219 2.99 5.98"; run; /* Read all filenames and put them into macro variables. The &FNAME variables store */ /* the names of the files only and &PEXT variables store the names of the files and */ /* the extensions. */ filename blah pipe 'ls ~/samp157/*.txt'; /* <------------------ */ data _null_; infile blah truncover end=last; length fname $80; /* <------------------ */ input fname; i+1; call symput('fname'||trim(left(put(i,8.))),scan(scan(trim(fname),-1,'/'),-2,'.')); /* <--- */ call symput('pext'||trim(left(put(i,8.))),scan(trim(fname),-1,'/')); /* <--- */ if last then call symput('total',trim(left(put(i,8.)))); run; /* Within a macro, run the PROC IMPORT code so that each filename is placed into */ /* the code appropriately. The PROC PRINT in the macro is just to show the */ /* results for testing purposes, and can be removed later. */ %macro test; %do i=1 %to &total; proc import datafile="~/samp157/&&pext&i" /* <------------------ */ out=work.&&fname&i dbms=dlm replace; delimiter=' '; getnames=no ; run; proc print data=work.&&fname&i;; title &&fname&i; run; %end; %mend; /* Invoke the macro */ %test