07-13-2017 12:36 PM
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"
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)?
07-13-2017 02:09 PM
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;
07-17-2017 10:46 AM
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)?