SAS Programming

DATA Step, Macro, Functions and more
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;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 1192 views
  • 0 likes
  • 2 in conversation