03-22-2018 11:42 AM - edited 03-22-2018 11:43 AM
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.
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)
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)
New Store Name Record(1)
Transaction Records (4)- Varying #'s
I have attached a sample text file in a similar format.
How would I import a file like this?
03-22-2018 12:19 PM
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:
input record_type $1 @;
if record_type='1' then input record_id $ 1-10 store_name $ 11-15 ..........;
else if record_type='4' then do;
input FirstName $ 1-15 LastName $ ........................;