View previous topic :: View next topic
|
Author |
Message |
Sharath S
New User
Joined: 18 Mar 2008 Posts: 5 Location: Mysore
|
|
|
|
I have a requirement to add the total number of records in the input file (Including Header and Trailer) and update the Trailer-Record-Count (PIC 9(09) Field in the trailer record.
And also all the records needs to be copied to output as it is.
For test I have taken One Header, One Trailer and One detail record.
The Code Is as given below:
Code: |
DATA INTEST;
INFILE INFILE ;
INPUT @1 RECTYPE $CHAR1. ;
IF (RECTYPE = 'H') THEN
DO;
COUNT = 1;
FILE OUTFILE;
PUT _INFILE_;
END;
IF (RECTYPE = 'D') THEN
DO;
COUNT = COUNT + 1;
FILE OUTFILE;
PUT _INFILE_;
END;
IF (RECTYPE = 'T') THEN
DO;
FILE OUTFILE;
PUT @1 'T'
@2 COUNT ZD 9;
END;
PROC PRINT DATA = INTEST(OBS=3);
RUN;
|
But the COUNT Field is not displaying the count properly. The COUNT = 1 is proper, but when I add +1 to it, the data is not proper.
The output of Proc Print is as given below:
Code: |
The SAS System
Obs RECTYPE COUNT ZD
1 H 1 .
2 D . .
3 T . .
|
Kindly let me know how to do this. |
|
Back to top |
|
|
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi Sharath,
I bet there was a message in your output along these lines
Code: |
NOTE: Missing values were generated as a result of performing an operation on mi
Each place is given by: (Number of times) at (Line):(Column).
1 at 12:17
|
Try this
Code: |
DATA INTEST;
RETAIN COUNT 0;
INFILE INFILE ;
|
You need a RETAIN statement.
Gerry |
|
Back to top |
|
|
Sharath S
New User
Joined: 18 Mar 2008 Posts: 5 Location: Mysore
|
|
|
|
Thanks Gerry.It is working fine. |
|
Back to top |
|
|
rajesh1183
New User
Joined: 07 Jan 2008 Posts: 98 Location: Hyderabad
|
|
|
|
You can also use
a automatic variable for finding the no. of records read from the input file...Since you know that there will be a header and trailer in ur input file, just subtract 2 from it at the end and update the trailer record. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
If you use the very nice SAS construct
then not only does this increment COUNT, but it also implicitly RETAINs it. |
|
Back to top |
|
|
|