|
View previous topic :: View next topic
|
| Author |
Message |
jm_green84
New User

Joined: 13 Dec 2006 Posts: 11 Location: ATL
|
|
|
|
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 |
|
 |
Robert Sample
Global Moderator

Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
| Why not just use a LAG function to retain the needed value(s) from the first read to the second read? |
|
| Back to top |
|
 |
jm_green84
New User

Joined: 13 Dec 2006 Posts: 11 Location: ATL
|
|
|
|
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 |
|
 |
Robert Sample
Global Moderator

Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
| 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 |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|