DATA Step, Macro, Functions and more

Reading a variable length file in Mainframe

Reply
Occasional Contributor
Posts: 17

Reading a variable length file in Mainframe

Hi SAS Expert Team, 

  I have a query reading the large VB file in Mainframes. File specs are below. 

 

File length = 11504

File Type = VB (Variable block)

Contains Records with variable length.  Example : If record 1 have the length of 765, then the rest of the characters in the observation 1 are null values. At position, 766 there will be CRLF that will specify the end of the observation. 

 

All the obseravations start with the date in the format 'YYYYMMDD' format. 

 

Many instances, thre is a need to filter data on basis of

 > DATE in the first 8 characters and

 > customer-id placed randomly in the observation 

 > Invoice Number placed at the fixed position of 65. 

 

How should I write a DATA step to read a Mainframe VB file and create sub-file based on the criteria. 

 

Regards,

Kumar.

 

Super User
Posts: 7,782

Re: Reading a variable length file in Mainframe

Posted in reply to AnalystKumar

Do you run SAS on the mainframe or another platform?

If another platform, do you have direct FTP access to the MF or do you receive the file via another path?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 17

Re: Reading a variable length file in Mainframe

Posted in reply to KurtBremser
I run SAS on MF platform and want to have the script for regular formatting of the VB file.

I have difficulty in writing a DATA step to read a VB Mainframe file. Once I;m able to do it, I can get the further processing ....
Super User
Posts: 7,782

Re: Reading a variable length file in Mainframe

Posted in reply to AnalystKumar

So, how far have you come already?

Did you have problems with the INFILE statement on z/OS?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 17

Re: Reading a variable length file in Mainframe

Posted in reply to KurtBremser
Yes, I made little progress.

DATE FILEOUT;
INFILE FILEIN1 LENGTH=LINELEN LRECL=11504 PAD;
INPUT VAR1 $1
DATE_VAR $8 @; /* ASSIGN THE LENGTH */
VARLEN=LINELEN - 9;
INPUT @10 REST_STRING $VARYING10991. VARLEN;
Run;

PROC PRINT DATA=FILEOUT;
RUN;

One more point I forgot to mention is that , CRLF exists in many parts of the message, But actual end of the record (or observation is) double-star **.

With the above DATE Step, data reads only until the first CRLF in the observations and then discards from there. Jumping on to the next line.
Super User
Posts: 7,782

Re: Reading a variable length file in Mainframe

Posted in reply to AnalystKumar

The first thing I'd try would be the RECFM=VB option in the infile statement. For VB files, z/OS maintains a separate 4-byte RDW (record descriptor word) that holds the current record length in its first two bytes. This eliminates the need for record separators.

Omitting the RECFM= options forces SAS to use any CRLF or similar combination (LF only, eg) as a record separator.

With RECVM=VB, you should not have line skips when a CRLF is encountered in the data.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 17

Re: Reading a variable length file in Mainframe

Posted in reply to KurtBremser
No Luck,

I have added RECFM=VB option on the DATA step. But still the observations get skips when it encounters a first CRLF
Occasional Contributor
Posts: 17

Re: Reading a variable length file in Mainframe

Posted in reply to AnalystKumar
I see the warning message in the log.
WARNING: Data too long for column "REST_STRING"; truncated to 128 characters to

before and after adding the RECFM=VB option
Super User
Posts: 7,782

Re: Reading a variable length file in Mainframe

Posted in reply to AnalystKumar

Try this:

data fileout;
infile filein1 recfm=vb lrecl=11504 truncover;
input
  var1 $1.
  date_var $8.
  rest_string $11493.
;
run;

If that doesn't fix your CRLF problem, you need to have those CRLFs stripped before you read into SAS.

Alternatively you could try to read with recfm=n (this reads the input as a non-formatted stream), read chunks of, say, 100 bytes into a large buffer until you find the line-delimiting '**' in your buffer, and work data out of the buffer. Then start reading again until you encounter the next '**' or EOF.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 8 replies
  • 796 views
  • 0 likes
  • 2 in conversation