BookmarkSubscribeRSS Feed
AnalystKumar
Obsidian | Level 7

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.

 

8 REPLIES 8
Kurt_Bremser
Super User

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?

AnalystKumar
Obsidian | Level 7
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 ....
AnalystKumar
Obsidian | Level 7
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.
Kurt_Bremser
Super User

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.

AnalystKumar
Obsidian | Level 7
No Luck,

I have added RECFM=VB option on the DATA step. But still the observations get skips when it encounters a first CRLF
AnalystKumar
Obsidian | Level 7
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
Kurt_Bremser
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 5272 views
  • 0 likes
  • 2 in conversation