Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Counting Number of Records using SAS.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL
Author Message
Sharath S

New User


Joined: 18 Mar 2008
Posts: 4
Location: Mysore

PostPosted: Sat May 24, 2008 10:58 am    Post subject: Counting Number of Records using SAS.
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
References
Moved: Sat May 24, 2008 10:18 pm by superk From CA Products to JCL
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 663

PostPosted: Sun May 25, 2008 6:07 am    Post subject:
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: 4
Location: Mysore

PostPosted: Mon May 26, 2008 11:28 am    Post subject: Reply to: Counting Number of Records using SAS.
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: 11
Location: Hyderabad

PostPosted: Tue May 27, 2008 5:25 pm    Post subject:
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: 497
Location: Richmond, Virginia

PostPosted: Tue May 27, 2008 6:01 pm    Post subject:
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
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL All times are GMT + 6 Hours
Page 1 of 1