Hi,
I have a plain text file I would like to import into SAS.
It is a fixed column text file, however there are multiple fixed lengths depending on the type of record.
Notes
1.) The type of record is indicated by the first number in each length
-I.E Records that start with 1: Store Indicator Lines 1 - 10 Record ID, 11-15 Store Name etc...
Records that start with 4: Transaction Indicator Lines 1- 15 FirstName, 15-30 Last Name etc...
Records that start with 4 flows over into 2 lines for every record
2.) Each group of Transactions are separated by a Store Record, however, they vary in then number of transactions
-I.E. Store Name (Records that start with 1)
space
Transaction Record #1(Records that start with 4)
Transaction Record #1 Continued
Transaction Record #2( Records that start with 4)
Transaction Record #2 Continued
Closing Line (Records that start with 6)
space
New Store Name Record(1)
Transaction Records (4)- Varying #'s
Closing Line
I have attached a sample text file in a similar format.
How would I import a file like this?
Thanks
You don't import it. You have to write a program. The overall form of the program is to read in the record type, without releasing the current line of data. Depending on the record type, read in the appropriate variables. It's actually more complex than that, because you have to decide what the final data set should look like. Most likely, you will end up repeating the store-level information for each transaction. In that case, the overall form of the program would look like this:
data want;
infile myfile;
input record_type $1 @;
if record_type='1' then input record_id $ 1-10 store_name $ 11-15 ..........;
retain store_name;
else if record_type='4' then do;
input FirstName $ 1-15 LastName $ ........................;
output;
end;
run;
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.