LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 1996, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 23 Oct 1996 00:00:22 -0700
Reply-To:     Karsten Self <kmself@IX.NETCOM.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Karsten Self <kmself@IX.NETCOM.COM>
Subject:      Re: Look Ahead Methodology:  99% Working!
Comments: To: statman@pacevm.dac.pace.edu

Gerry, intersting post. I'm replying blind (from home, no SAS, no manuals), Ian will probably do his thing and correct my mistakes.

Misquoting from memory, there are several conditions which cause a SAS data step to stop executing, including reaching EOF on a raw data file. This is documented in the DATA STEP portion of the "SAS Language, Reference" manual, titled something like "stopping/halting the DATA step".

I believe that what is happening is your LASTREC infile option (and label) are being triggered on what you intend to be the *next to last* record -- an off-by-one error. If this is the case, then the following describes the situation:

You intend: SAS reads the next-to-last record, checks next record for remainder of JOURNAL field. Data step returns for one final pass, on which the LASTREC condition is triggered.

SAS does: Reads next-to-last record. Checks next (final) record for remainder of JOURNAL. Finds EOF. Executes LASTREC label.

Cures (several possible):

Put your last-record processing on the LASTREC label -- input and output the final record. Make sure that the remainder of your processing is consistent with proper processing of the n-1th record. I would insert some diagnostic code (PUT statements with data values and data step loop (_N_) value) in the LASTREC label code block to test this. You might also try running your code through the DATA Step debugger for a small data set.

I believe there may be an "ignore eof" type option on infile, though I don't know of the top of my head what it is. You'd probably have to substitute your own halting logic if you used it, to prevent some rather nasty SAS errors.

BTW & FWIW -- very clear post & a good presentation of your problem. And the tylenol is right next to the JD.

============================================================================ Original post ============================================================================

Date: Mon, 21 Oct 1996 17:21:26 EDT From: Gerry <STATMAN@PACEVM.DAC.PACE.EDU> Subject: Look Ahead Methodology: 99% Working !

The Task ********

The problem is that for some of the records, the first field, named JOURNAL, is folded across two or more lines. For example: <...> The solution requires the program to "look ahead" to the next record to see if the first position is filled, indicating a record where JOURNAL is on one line, or blank, indicating that the JOURNAL field is folded across 2 or more lines. <...> The program attached below almost works, except that it will not output the last record in the file. According to the SASLOG, all of the records in the file are read in properly. <...> I'm sure I must be overlooking something obvious, or that I missed in the manual, but for the life of me, I can't find it and its driving me crazy ! <...> I apologize for the length of this note, but when asking for help, I think it is better to provide too much information than not enough. Any and all help will be gratefully appreciated -- now where's that bottle of tylenol !

Gerard T. Pauline | Pace University | Phone: (212) 346-1706 Dept of Academic Computing | Internet: Gerry @ Pace.Edu 1 Pace Plaza, Office Y-25 | Bitnet: Gerry @ Pacevm New York, NY 10038 | Web: http://www.pace.edu/acadcomp

-------------------------------- Program -------------------------------

Filename INPDATA 'LIBRARY DATABASE A1' ; Options LS=95 NODATE ;

Data LIBRARY (Keep=JOURNAL RECORD) ; Infile INPDATA Eof=LASTREC ;

Length JOURNAL $ 200 RECORD $ 41 ;

Array JTXT {5} $ 38 _Temporary_ ; Array RTXT {5} $ 41 _Temporary_ ;

I = 1 ; /* Initialize Array Index */ JTXT{2} = '' ; /* Blank Out Array Elements From Previous */ JTXT{3} = '' ; /* Record, Element 1 Is Always Populated */ JTXT{4} = '' ; /* In Each Array */ JTXT{5} = '' ; RTXT{2} = '' ; RTXT{3} = '' ; RTXT{4} = '' ; RTXT{5} = '' ;

Do While (1) ;

/*--- Read In Current Record, "Look Ahead" To The Next Record ---*/

Input @1 JTXT{I} $Char38. @40 RTXT{I} $Char41. / @1 RCHK1 $1. @40 RCHK2 $Char41. @@ ;

If ((RCHK1 = ' ') | ((RCHK1 ^= ' ') & (Compress(RCHK2) = ''))) Then Do ; /* Journal Field Is "Folded" */ I + 1 ; /* Increment The Array Subscript */ Continue ; /* Populate The Next JTXT Element */ End ; Else Leave ; /* Journal Field Is All On One Line */

End ; /* End DO WHILE (1) Loop */

/*--- Form The JOURNAL & RECORD Variables, And Output To Dataset ---*/

JOURNAL = Trim(JTXT{1}) || ' ' || Trim(JTXT{2}) || ' ' || Trim(JTXT{3}) || ' ' || Trim(JTXT{4}) || ' ' || Trim(JTXT{5}) ;

RECORD = RTXT{1} ;

Output LIBRARY ;

Return ; /* Not At E-O-F Yet */

LASTREC: Output LIBRARY ; /* Account For The Last (?) Record ... */ /* At Least I Thought I Was ! */ Return ;

Run ; ---------------------------------------- Karsten Self / kmself@ix.netcom.com

What part of gestalt don't you understand?


Back to: Top of message | Previous page | Main SAS-L page