Dear SAS community,
I wish to import data sets for circa 60 .txt. files to SAS. Each file's data set consists of a single line of the letters and numbers 123RW in some combination. Due to the length of the data set, it is divided into two lines.
Attached are three examples of the data sets in the files I am working with.
I wish to have the data transposed into a single column with the variable name "stages".
I also wish to retain the file name of the individual files and insert it as a variable in each file. Thus, for each observation in the data set variable "stages", it should be labeled with the file name (e.g., "ID") in an adjacent column.
I am using version 9.4 SAS
I have looked online and have made some attempts (see script below), but I have not been successful. Can you please offer me any help or advice?
Sincerely,
Ian
data WANT;
infile 'C:\*.txt' dlm='09'x dsd truncover;
input @@;
run;
Try this:
data WANT;
length id fname $200;
infile 'C:\*.txt' filename=fname;
id = fname;
input stages $1. @@;
run;
Do you need to read single characters, or a fixed length of, say, 5?
Hi Kurt Bremser,
Thanks for your reply. Single characters. Each observation should be a single character.
-Ian
Try this:
data WANT;
length id fname $200;
infile 'C:\*.txt' filename=fname;
id = fname;
input stages $1. @@;
run;
Hi Kurt Bremser,
Thank you yet again. I can't tell you how much I appreciate your help!
Best,
Ian
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.