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

Counting Number of Records using SAS.


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Sharath S

New User


Joined: 18 Mar 2008
Posts: 5
Location: Mysore

PostPosted: Sat May 24, 2008 10:58 am
Reply with quote

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
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Sun May 25, 2008 6:07 am
Reply with quote

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
View user's profile Send private message
Sharath S

New User


Joined: 18 Mar 2008
Posts: 5
Location: Mysore

PostPosted: Mon May 26, 2008 11:28 am
Reply with quote

Thanks Gerry.It is working fine.
Back to top
View user's profile Send private message
rajesh1183

New User


Joined: 07 Jan 2008
Posts: 98
Location: Hyderabad

PostPosted: Tue May 27, 2008 5:25 pm
Reply with quote

You can also use
Code:
_N_
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
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Tue May 27, 2008 6:01 pm
Reply with quote

If you use the very nice SAS construct

Code:
COUNT + 1;


then not only does this increment COUNT, but it also implicitly RETAINs it.
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 -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 0
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
Search our Forums:

Back to Top