BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
data_null__
Jade | Level 19

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.

FriedEgg
SAS Employee

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 16762 views
  • 2 likes
  • 6 in conversation