Say that in a folder I have over 100+ .dat
files with no common generic file names. For instance, the files are not named f001
, f002
, f003
(you get the pattern). The names are random. I need to parse these .dat
files into SAS files. Each files have the same column/attributes. I use the following code to parse one of the .dat
file:
data have;
infile 'C:\SAS\have.dat' dsd dlm='|';
input var1 var2 var3$;run;
The code is the same for each .dat
files. Is there a way in SAS to simply parse all the files in a folder and name these SAS files the same as their original .dat
. I want all the files to be separated and not under one SAS file.
[UPDATE] I first start by reading all the filenames in my folder using the following SAS command:
data yfiles;
keep filename;
length fref $
8 filename $ 80;
rc = filename(fref,
'Y:\Files\Exchanges');
if rc = 0 then do ;
did = dopen(fref);
rc = filename(fref); end;
else do; length msg $200.;
msg = sysmsg();
put msg=; did =.;
end;
if did <=0 then putlog
'ERR' 'OR: Unable to open directory.';
dnum = dnum(did);
do i =1 to dnum;
filename = dread(did, i);
/* If this entry is a file, then output. */
fid = mopen(did, filename);
if fid >0 then output;
end;
rc = dclose(did);
run;
In yfiles
I have all the names of my .dat
datasets.
Now, how can I loop through each .dat
files names of my yfiles
dataset to apply the above parsing code?