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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.