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)
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.