I have a data file as attached. The below is the code to revise the data.
data want;
infile 'C:\Users\AAB006.txt' lrecl=30000;
input;
x=countw(_infile_);
do i=1 to x;
Num=scan(_infile_, i, " ");
output;
end;
drop i x;
run;
My next challenge is that: There are thousands of such files in a folder. Is there way that the SAS code can automatically get the files' names, and process each of them automatically, rather than manually do it one by one. Appreciate your help.
Use the FILENAME option on the INFILE statement.
Here is an example that will keep the name and also number the files, the rows and column location within the row.
data want ;
length filename fn $200 ;
infile '*.txt' filename=fn eov=eov length=ll column=cc truncover ;
fileno+1;
do row=1 by 1 until (eov) ;
do col=1 by 1 until (cc>ll);
input num @ ;
filename=fn ;
output;
end;
input;
end;
run;
Yes, search on here. The method is typically:
If you need one output file per text file you can use the method here.
There are other solutions listed on the forum as well.
Use the FILENAME option on the INFILE statement.
Here is an example that will keep the name and also number the files, the rows and column location within the row.
data want ;
length filename fn $200 ;
infile '*.txt' filename=fn eov=eov length=ll column=cc truncover ;
fileno+1;
do row=1 by 1 until (eov) ;
do col=1 by 1 until (cc>ll);
input num @ ;
filename=fn ;
output;
end;
input;
end;
run;
I really love Tom's answer. So simple, but perfectly match my needs.
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!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.