IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

how to tell the pointer to go bac to the 1st rec in input


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
jm_green84

New User


Joined: 13 Dec 2006
Posts: 11
Location: ATL

PostPosted: Sat Jan 24, 2009 1:32 am
Reply with quote

Can anyone help me out with this one?

I'm reading in a file and doing some checks on it before processing it. and I'm reading in my header record on line one and then going to line two to read in another var. Now once I have my second var from line two, how can I tell sas in the input statement to go back to line 1 again to get my third value?

My file consist of the first rec being the HEADER, it also has the File Creation date on this line. Next line (line 2) is were my detail record starts, with actual ppl data. and each row that starts with a "02" is a valid record. the number of detail records vary from file to file. next after all the detail records the last rec is a Trailer record. Now I'm doing these checks because we apparently have some invalid files on our system, and don't want to process them.

so a valid file would look like

HEADER 20090123
02johndoe
02janedoe
02 ex....
TRAILER

The problem I am having is
- first I'm checking to make sure the file is valid by make sur ethe first record is indeed a HEADER row

-second I'm checking, "02" row for detail records. By say ok if your first row is a HEADER and your 2nd row starts with a "02" then your mored than likely a valid file , and **heres where my code isn't working. I then want it to go back to record 1 and now pull the File Creation date.**

If anyone knows out to make the pointer go back in a INPUT statement plz help me out, Thanks.

Code:

DATA GOOD NOTVALID;                                               
 INFILE SASI1 END = NODATA;                                       
  BADGDG = %ADDTICKS(%FILEDATA(SASI1,1));                         
  INPUT @01 CHECK1  $CHAR6.@;                                     
    IF (CHECK1 = 'HEADER' AND _N_ ¬= 1) OR (CHECK1 ¬= 'HEADER' AND
       _N_ =1 ) THEN DO;                                         
       FLG='BADFILE';                                             
       OUTPUT NOTVALID;                                           
    END;                                                         
                                                                 
    ELSE IF CHECK1='HEADER' AND _N_ =1 THEN DO;                   
            INPUT / @01  REC02 $CHAR02.@;                         
         IF REC02 ¬= '02' THEN DO;                               
            FLG='BADFILE';                                       
            OUTPUT NOTVALID;                                     
         END;                                                     
     END;                                                         
                                                                 
 IF FLG ¬='BADFILE' THEN DO;                                     
    RETAIN FILEDT;                         
    INPUT    @01 CHECK1 $CHAR6.           
                @07 FILEDT YYMMDD08.@;       
      IF CHECK1='HEADER' THEN DO;         
       CREDAT = FILEDT;                   
      END;                                 
                                           
    ELSE DO;                               
       INPUT @04  SSN              $CHAR09.
             @26  TRANSID          $CHAR06.
             @32  RATE             17.;   
       OUTPUT GOOD;                       
    END;                                   
 END;                                     
%PRINTEM(GOOD,TEST=&TORP);                 
%PRINTEM(NOTVALID,TEST=&TORP);                 
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sat Jan 24, 2009 2:12 am
Reply with quote

Why not just use a LAG function to retain the needed value(s) from the first read to the second read?
Back to top
View user's profile Send private message
jm_green84

New User


Joined: 13 Dec 2006
Posts: 11
Location: ATL

PostPosted: Sat Jan 24, 2009 2:33 am
Reply with quote

Thanks for the reponse,

I will try the LAG func, I actually never used it but anythings worth a try right now.

How does it work?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sat Jan 24, 2009 2:48 am
Reply with quote

Code:
INPUT X ...
Y = LAG1(X) ;
causes Y to have the same values as X, just one observation later. So if X is read as 1, 2, 3, 4 ... then Y will have values missing, 1, 2, 3, ....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts force tablespace using LISTDEF input DB2 1
No new posts Two input files & writing counter... DFSORT/ICETOOL 12
No new posts Use input file with OMIT rcd keys? DFSORT/ICETOOL 15
Search our Forums:

Back to Top