Hi all,
I have a directory &dir, with several files in txt in it. Some files begin by "FILE_" others don't.
The files beginning by "FILE_" have the same format, "hopefully"
A $6
B $12
I just need to create a table Z, as an append of all files beginning by "FILE_" whatever is the number of files in the directory dir.
I am a bit lost on how to do that.
Can someone help me on 'easy' problem (I am a SAS almost beginner)?
Thanks
You could use sas functions to open a directory and get a list of file names in that directory, but this problem is also amenable to using an operating system command to trivially list the desired files names. That list can be put in an %include file, as in:
filename mypipe pipe "dir/b c:\temp\FILE_*.txt";
filename tmp temp ;
data _null_;
infile mypipe truncover end=eod;
input filnam $50.;
filnam=cats('c:\temp\',filnam);
file tmp;
if _n_=1 then put 'infile "(' @;
else put ',' @ ;
put filnam @;
if eod then put ')";';
run;
options source2;
data want;
%include tmp ;
*input x y;
input (a b) ($6. $12.);
run;
Notes:
Hello mkeintz,
Thanks for the reply.
I got an issue when I try to "include tmp":
ERROR: Physical file does not exist, /apps/sas94/sasconfig/Lev1/SASMain/c:\temp/usr/bin/ksh:.
I am indeed working on Windows.
I think it means the file filenam wasn't created as planned in the first datastep?
I don't really understand the path file because you are mixing a SAS path with a Windows path. Is it normal?
Or maybe I am not granted to write (I see a Lev1 in the path that's why I think this)?
Thanks
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.