Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extraneous Lines in Output

Status
Not open for further replies.

ks01

MIS
Aug 11, 2002
110
0
0
US
Hi everyone …

I need some help with my SAS program. I am getting some unexpected results in my ouput and I am not sure where to go to resolve them. I run this via batch JCL on a mainframe running z/OS.

Here is my program:

Code:
OPTIONS;                                 
DATA R001 (KEEP= ISSUENUM SATEFFDT LSTGDATA ACCTBIN ACTNCD REGNSUMM PRGEDT);
INFILE INPUT1;                           
  INPUT @01 RECTYP $CHAR1. @ ;           
    IF RECTYP = '0' THEN                 
       DO;                               
          INPUT @09 ISSUENUM $CHAR2.     
                @12 SATEFFDT MMDDYY6. @ ;
       END;                              
       RETAIN SATEFFDT;                  
    IF RECTYP = '1' THEN                 
       DO;                               
          INPUT @03 LSTGDATA $CHAR16.    
                @03 ACCTBIN  $CHAR6.     
                @22 ACTNCD   $CHAR2.     
                @28 REGNSUMM $CHAR16.    
                @45 PRGEDT   YYMMDD6. @ ;
       END;                   
  FILE OUTPUT1;               
  IF _N_ = 1 THEN DO ;        
  PUT @01  'ACCOUNT NUMBER'   
      @21  '0123456789ABCDEF' 
      @38  'EFFECTIVE' ;      
      END ;                   
  PUT @01  LSTGDATA           
      @21  REGNSUMM           
      @38  SATEFFDT MMDDYY6. ;
  RETURN ;
Here is a sample of the output:

[tt]ACCOUNT NUMBER 0123456789ABCDEF EFFECTIVE
080908
XXXXXXXXXXXXXXXX 0000001001000100 080908
XXXXXXXXXXXXXXXX 1000000000111011 080908
080908[/tt]

What is appearing in my ouput that is unwanted is line two and line five. Does anyone have a suggestion on how to prevent lines two and five from printing?

Also, a second question, in my SAS log, there appears a segment like the following:

[tt]62,899,234 RECORDS WERE READ FROM THE INFILE INPUT1.
10,916 RECORDS WERE WRITTEN TO THE FILE OUTPUT1.
THE DATA SET WORK.R001 HAS 10,918 OBSERVATIONS AND 7 VARIABLES.
THE DATA STATEMENT USED 229.87 CPU SECONDS AND 12831K.[/tt]

Does anyone know if there is a way to append my output file with this blurb?

Thanks in advance everyone!

ks01
 
Hi Ks01,
The output records 2 and 5, are basically records where RECTYP is 0, and therefore, the fields being written out aren't present.
I'd suggest looking closely at the input data and stepping through your code in your head and making sure you fully understand what it is doing (try explaining it to someone else if you still can't see the problem. Even if the someone else doesn't know SAS, it can help, it's a debugging tool known as "Rubber Ducking").
Basically though, your first input record has a rectyp=0, your second record has rectyp=1, third record again has rectyp=1 and 4th records has rectyp=0 (assuming there is only 1 and 0 values) again.
I suspect you only want to write out record where rectyp=1.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Hi Chris ...

Thanks for the feedback.

Yes, you are correct. Record type 0 is the header record which identifies the effective date of my data. There are also some other values in the header record I may need someday.

Right now, the only value I'm using from the header record is the effective date and I want to use that date in each record ... I'm using it in my PUT statement.

Do you have a suggestion on how I can accomplish this without getting these empty records from reading in record type 0?

Thanks ...

Kent
 
Yeah. All you need to do is move your put statement into the IF section.
I've also made some other formatting changes to the code below.
RETAIN statements I believe are read irrespective of where in the step they are typed, but I might be wrong on that one.
The trailing @'s on the 2nd and 3rd input step I believe I not needed, and there were a couple of DO... END constructions that weren't needed either. It's possible that this might run slightly faster...
Code:
OPTIONS;                                 
DATA R001 (KEEP= ISSUENUM SATEFFDT LSTGDATA ACCTBIN ACTNCD REGNSUMM PRGEDT);
  INFILE INPUT1;  
  FILE OUTPUT1; 

  RETAIN SATEFFDT;  
              
  IF _N_ = 1 THEN      
    PUT @01  'ACCOUNT NUMBER'   
        @21  '0123456789ABCDEF' 
        @38  'EFFECTIVE' ;  
                      
  INPUT @01 RECTYP $CHAR1. @ ;           
    IF RECTYP = '0' THEN                 
          INPUT @09 ISSUENUM $CHAR2.     
                @12 SATEFFDT MMDDYY6. ;
                         
    IF RECTYP = '1' THEN                 
       DO;                               
          INPUT @03 LSTGDATA $CHAR16.    
                @03 ACCTBIN  $CHAR6.     
                @22 ACTNCD   $CHAR2.     
                @28 REGNSUMM $CHAR16.    
                @45 PRGEDT   YYMMDD6. ;

          PUT @01  LSTGDATA           
              @21  REGNSUMM           
              @38  SATEFFDT MMDDYY6. ;
       END;                   
                 
RUN;

Nice to know there's still some people out there using JCL to submit these programs, that's where I initially started learning SAS working at a bank on a mainframe. :)

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Hi Chris ...

As usual, your advice is right on. Thank you!

Do you know of anyone way to get that snippet from the SAS log into the output ... like a footer?

[tt]62,899,234 RECORDS WERE READ FROM THE INFILE INPUT1.
10,916 RECORDS WERE WRITTEN TO THE FILE OUTPUT1.
THE DATA SET WORK.R001 HAS 10,918 OBSERVATIONS AND 7 VARIABLES.
THE DATA STATEMENT USED 229.87 CPU SECONDS AND 12831K.[/tt]

Thanks!

Kent
 
Copy and paste? :)
You can get access to the number of records in a dataset by a few means.
You can use proc sql to get the information from dictionary.tables and load it into a macro variable, or use proc sql to do a count(*) on the dataset to get the number of records.
something like this:-
Code:
proc sql;
   select count(*)
   into :cnt
   from R001
   ;

However, I've just realised that you have the in and out in 1 datastep, so I'd probably do something like this:-
Code:
OPTIONS;                                 
DATA R001 (KEEP= ISSUENUM SATEFFDT LSTGDATA ACCTBIN ACTNCD REGNSUMM PRGEDT);
  INFILE INPUT1 end=eof;  
  FILE OUTPUT1; 

  RETAIN SATEFFDT;  
              
  IF _N_ = 1 THEN      
    PUT @01  'ACCOUNT NUMBER'   
        @21  '0123456789ABCDEF' 
        @38  'EFFECTIVE' ;  
                      
  INPUT @01 RECTYP $CHAR1. @ ;           
    IF RECTYP = '0' THEN                 
          INPUT @09 ISSUENUM $CHAR2.     
                @12 SATEFFDT MMDDYY6. ;
                         
    IF RECTYP = '1' THEN                 
       DO;                               
          INPUT @03 LSTGDATA $CHAR16.    
                @03 ACCTBIN  $CHAR6.     
                @22 ACTNCD   $CHAR2.     
                @28 REGNSUMM $CHAR16.    
                @45 PRGEDT   YYMMDD6. ;

          PUT @01  LSTGDATA           
              @21  REGNSUMM           
              @38  SATEFFDT MMDDYY6. ;
       END; 
   if eof then
   do;
      * Footer *;
      put "Records = " _N_;
   end;
                
RUN;

Play around with that, you might need to put a counter in the DO that outputs records to keep track of the number of records written out, I think _n_ will give you the number of records read in...
Should get you started anyway.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top