BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rakesh1212
Fluorite | Level 6

Hi Team,

 

I have a requirement to convert COBOL raw dataset to readable format, to achieve this i am reading a cobol copy book and converting each field type to SAS equivalent field types.

 

Now i am inputting the COBOL raw data file to the mainframe JCL(Job) which has SAS parameters in the control card and want my output in CSV format.

 

I want my SAS to read the COBOL raw data file and convert it to corresponding field type mentioned and print the output in the file which should be in CSV format.

 

Thanks & Regards,

rakesh MS

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

To copy a screen from Personal communications, just use the mouse to mark the area and do Edit - Copy from the menu.

 

As I expected, you have a fixed format file, no delimiters.

A data step to read that file should look like

data want;
infile (use the fileref from the JCL DSN) lrecl=(value as shown) recfm=f;
input
  x71340d_va_hdr_rec_id   1.
  x71340d_va_hdr_rvsl_flag  $1.

and so on. Note that date and time values are only recognizable by name, so you will have to do the conversion all by yourself; I also see that one date comes in a zoned length 8 field, while the other is in a packed decimal length 4. So you need to inspect the actual contents for that.

For PD fields, use the s370fpd informat.

Since you have no reliable means of distiguishing date and time values from other, "normal" numbers, you will have to write most of the data step by hand.

And I would clearly not use variable names like A0001, A0002 and so on. That's 1960s style coding.

View solution in original post

24 REPLIES 24
rakesh1212
Fluorite | Level 6

Hi Kurt,

 

Please find the scrren shots attached. I have no access to take the screen prints of the Panel.

 

 

Please note : Input file (COBOL dataset) is in Fixed block format.

Regards,

Rakesh MS


IMG_3845.JPGIMG_3846.JPGIMG_3847.JPGIMG_3848.JPG
Kurt_Bremser
Super User

To copy a screen from Personal communications, just use the mouse to mark the area and do Edit - Copy from the menu.

 

As I expected, you have a fixed format file, no delimiters.

A data step to read that file should look like

data want;
infile (use the fileref from the JCL DSN) lrecl=(value as shown) recfm=f;
input
  x71340d_va_hdr_rec_id   1.
  x71340d_va_hdr_rvsl_flag  $1.

and so on. Note that date and time values are only recognizable by name, so you will have to do the conversion all by yourself; I also see that one date comes in a zoned length 8 field, while the other is in a packed decimal length 4. So you need to inspect the actual contents for that.

For PD fields, use the s370fpd informat.

Since you have no reliable means of distiguishing date and time values from other, "normal" numbers, you will have to write most of the data step by hand.

And I would clearly not use variable names like A0001, A0002 and so on. That's 1960s style coding.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, please post clear examples of data/programs etc associated with the question.  I don't have Cobol files lying around to use.  From a quick Google copybook is nothing more than a Cobol program?  What is the data file format, is it binary or text.  If its text then simply a matter of identifying columns/rows an reading in using a datastep.  If its binary then this is quite a bit harder.

Here is a link you may find useful:

https://stackoverflow.com/questions/4877379/reading-a-cobol-generated-file

 

rakesh1212
Fluorite | Level 6
Hi kurt,

Thanks for looking into this. Will incorporate all the comments given. Just a concern, where do I mention the output file which I need it in CSV format.

Regards,
Rakesh
Kurt_Bremser
Super User

You will need another dsn in the JCL script that gives you a reference for the output file; use that as a fileref within your SAS program, and when writing from your dataset, add the corresponding options (lrecl= and recfm=) to the file statement in the data _null_ step.

ie

In the JCL you have a DSN for OUT

In SAS:

data _null_;
set your_dataset;
file out recfm=vb lrecl=1000 dlm=',' dsd;
put
  /* variables */
;
run;
Tom
Super User Tom
Super User

Unless your file is huge (more than 100 Gigabytes?) I would first read it into a SAS dataset and then generate the CSV file (if needed).

So first make a data step to read the file.

data mydata;
   infile .... ;
   input .... ;
   ....
run;

You can use PROC EXPORT to generate a CSV file.

proc export data=mydata file='mydata.csv' dbms=dlm ;
  delimiter=',';
run;

Or you can very easily write a CSV file directly using a data step, especially if you do not need to include a header row.

data _null_;
  set mydata;
  file 'mydata.csv' dsd ;
  put (_all_) (+0);
run;

If the file is really large then you can use the FILE and PUT statement of the last data step as part of the step that reads the COBOL file and skip making even a SAS WORK dataset.

rakesh1212
Fluorite | Level 6

Hi tom,

 Ihave two Questions for you 

1) i am trying to use data _null_;
set temp1;
file 'output file' dlm=',' dsd ;
put (_all_) (+0);
run;

How to switch on the labels. I need the labels on the top row and then the values below it.

 

2) I tried using 

proc export data=mydata file='mydata.csv' dbms=dlm ;
  delimiter=',';
run;

proc export data=temp1 file='outputfile' dbms=dlm;

   delimiter=',';

run;

 

Regards,

Rakesh MS

run;

 

It gives me error ; Statement not valid or it is used out of proper order 

 

Delimiter=','

tatement not valid or it is used out of proper order

rakesh1212
Fluorite | Level 6

kurt,

 

How do we display the labels  ? and one more thing, can we dynamically convert the data to readable format with out knowing their data types ?. Actually there are lot of redefine clauses in the mainframe copy book. Field which is getting redefined has a different field type compared to redefined field.

 

Can we handle header and trailer of the file separately ??, header and trailer data is been adding prior in every data that is present.

 

let me know if you need any more information

 

Regards,

Rakesh MS

 

 

Kurt_Bremser
Super User

In a "manual" data step, you need to add the header line in the code:

data _null_;
set temp1;
file 'output file' dlm=',' dsd ;
if _n_ = 1 then put "headertext,in,correct,format,comes,here";
put (_all_) (+0);
run;
Kurt_Bremser
Super User

What do you mean by "without knowing their data types"? If you don't know your data, how are you supposed to work with it? Read the documentation and work from that. Data without documentation is returned to sender with a corresponding nastygram.

rakesh1212
Fluorite | Level 6

I asked you this question becasue of redefine clause in the COBOL copy book. Copy book fields are internally redefined so that they use the same space to store but when they get redefined they are defined with different data types.

 

Can you help me with label syntax. I want a label for every field and data to be under it in the output file.

 

 

Regards,

Rakesh MS

Kurt_Bremser
Super User

If you do not have sufficient documentation and there is no way to get it (HIGHLY unlikely as COBOL is typically used in environments where everybody was extremely anal about proper documentation. Think banking, insurance, and the like), then you need to start reading the COBOL sources to get a picture of what the data files really contain.

 

For header lines, see this example using SASHELP.CLASS:

data _null_;
set sashelp.class;
file '$HOME/sashelp.csv' dlm=',';
if _n_ = 1 then put 'Name,Sex,Age,Height,Weight';
put name sex age height weight;
run;

The resulting file then looks like this:

Name,Sex,Age,Height,Weight
Alfred,M,14,69,112.5
Alice,F,13,56.5,84
Barbara,F,13,65.3,98
Carol,F,14,62.8,102.5
Henry,M,14,63.5,102.5
James,M,12,57.3,83
Jane,F,12,59.8,84.5
Janet,F,15,62.5,112.5
Jeffrey,M,13,62.5,84
John,M,12,59,99.5
Joyce,F,11,51.3,50.5
Judy,F,14,64.3,90
Louise,F,12,56.3,77
Mary,F,15,66.5,112
Philip,M,16,72,150
Robert,M,12,64.8,128
Ronald,M,15,67,133
Thomas,M,11,57.5,85
William,M,15,66.5,112

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 24 replies
  • 4010 views
  • 4 likes
  • 4 in conversation