BookmarkSubscribeRSS Feed
iluvsas
Calcite | Level 5

I have a test.dat cobol file in the below format and need to read this file and convert to a sas

dataset.

The first row is the header and the last row is the trailer record in the test.dat file.
I need to exclude the header and trailer records when I read and convert the file to a sas dataset.

Any thoughts to read these files in SAS in batch mode as I have 7 files of the same format.


Test.dat
--------

101111STR1 EXTRACT FILE       2012040120120402
15666+12345+4174.99YJohn Doe            1234
15667+12346+6179.99YJohn Doe2           1235
103455STR1 EXTRACT FILE       2012040120120402000000+1234.99

The cobol file layout for the fields is as below:

roll-type    pic X(01)
pno          pic X(04)
p1-num-s  pic X(01)
p1-num    pic X(05)
a1-s        pic X(01)
a1           pic 9(4).99
code       pic X(01)
name      pic X(20)
code2     pic x(04)


1 REPLY 1
RMP
SAS Employee RMP
SAS Employee

something like this would work.

data cobol(drop=rectype);

  infile cards truncover;

   input rectype $200. @;

   if index(rectype,'EXTRACT FILE') then return;

   input rolltype $1 pno $4 p1_num_s $1 p1_num $5;

output;

datalines;

101111STR1 EXTRACT FILE       2012040120120402

15666+12345+4174.99YJohn Doe            1234

15667+12346+6179.99YJohn Doe2           1235

103455STR1 EXTRACT FILE       2012040120120402000000+1234.99

;

run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1312 views
  • 0 likes
  • 2 in conversation