Here's how I like to do these. The first step converts the data elements you need into a SAS dataset. I got one working based on the data you posted; you'll probably need to fiddle with it based on your full data. The idea is to keep ID and account name from the header rows, and the variables you need from the transaction rows. Check that the data in "have" look okay. Then in the second step, if the record is a header, just retain the ID and account name; they will automatically populate the transaction rows, which are the only ones output. Tom data have; /* Turn the report format into a SAS dataset */ length rowtype TransType $ 32 AccountName_in $ 64; drop rowtype; input; /* get a record, and hold it in internal variable _infile_ */ rowtype = _infile_ || repeat(" ", 32); /* Make sure we have at least 32 characters to work with */ if substr(rowtype, 1, 7) = "Loan #:" then do; ID_in = scan(_infile_, 2, '09'x, "O"); /* 09 is hexadecimal for a tab character */ AccountName_in = scan(_infile_, 4, '09'x, "O"); output; end; else if substr(rowtype, 1, 6) = "Page #" | substr(rowtype, 1, 4) = "Date" | substr(rowtype, 1, 11) = "Loan Totals" then ; /* we don't need anything from these lines */ else do; TransDate = scan(_infile_, 1, '09'x, "O"); TransType = scan(_infile_, 2, '09'x, "O"); TransAmount = input(scan(_infile_, 3, '09'x, "O"), best32.); TransDisbursed = input(scan(_infile_, 4, '09'x, "O"), best32.); TransCapitalized = input(scan(_infile_, 5, '09'x, "O"), best32.); TransRecovery = input(scan(_infile_, 6, '09'x, "O"), best32.); TransBalance = input(scan(_infile_, 7, '09'x, "O"), best32.); output; end; cards; Loan #: 04-0026 Account Name: Chew Dewey Barbeque Page #: 11 Date Action Amount Disbursed Capitalized Recovery Balance 07/09/2004 Commitment 1000 0 0 0 0 07/09/2004 Advance: Principal 1000 1000 0 0 1000 Loan Totals 1000 0 0 0 Loan #: 04-0037 Account Name: Salmon River Plaza 07/12/2004 Commitment 27500 0 0 0 0 07/12/2004 Advance: Principal 27500 27500 0 0 27500 08/11/2004 Payment: Customized 600.8 0 0 0 27059.62 09/22/2004 Payment: Customized 545.8 0 0 0 26734.81 run; data want; set have; length AccountName $ 64; retain ID AccountName; drop ID_in AccountName_in; if ID_in ^= "" then do; /* keep the id and account in our retained variables */ ID = ID_in; AccountName = AccountName_in; end; else output; /* this is a transaction row, and we've retained the ID and account */ run;
... View more