BookmarkSubscribeRSS Feed
jackx
Calcite | Level 5

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

 

1 REPLY 1
Astounding
PROC Star

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1109 views
  • 3 likes
  • 2 in conversation