Look up EOV INFILE statement option it is designed to detect the start of a new file in a concatenation. Much easier than comparing file names.
Thanks _null_, I had forgotten about that option.
/* create some dummy files */
data _null_;
do i=1 to 3;
call execute('filename file' || strip(i) || ' "/home/friedegg/file' || strip(i) || '.txt";');
call execute('data _null_;');
call execute(' file file' || strip(i) || ';');
call execute(' put "a b c d e";');
call execute(' put "f g h i j";');
call execute('run;');
end;
run;
filename indata '/home/mkastin/file*.txt';
data want;
length _file _filex $512;
infile indata eov=_firstrec_;
input (blah1-blah5) (:$1.);
if _n_ or _firstrec_ then delete; /* _firstrec_ will =1 for all files first record except the first */
run;
/* remove this junk */
data _null_;
do i=1 to 3;
call execute('x "rm -f /home/friedegg/file' || strip(i) || '.txt";');
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.