Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ 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 & VSAM
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    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

gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1703
Location: Australia

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: 5
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: 98
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

Active Member


Joined: 31 Oct 2006
Posts: 964
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts SMTP the current generation number of... Jyothi Kulunde JCL & VSAM 4 Thu May 04, 2017 4:08 pm
No new posts Edit large number of datasets (QSAM) zh_lad TSO/ISPF 3 Tue Apr 04, 2017 6:08 pm
No new posts how to mask the phone number kumarinfy DB2 4 Mon Apr 03, 2017 5:23 pm
No new posts what is meaning of the number in dcl Martylin PL/I & Assembler 2 Thu Mar 09, 2017 7:18 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us