BookmarkSubscribeRSS Feed
Phil20
Obsidian | Level 7

Dear SAS expertise, 

I need a help. I have a mainframe flat file and its layout (copybook). I can open it in file manager to see the data in readable format. But I want to copy this file to an output with the layout and convert few packed decimal fields into numeric format. I payed with file manager and no luck. Can someone share some sudo code how to copy a flat file to table formatted output file using input file and its copybook layout. Appreciate your feedback. Thanks

13 REPLIES 13
Phil20
Obsidian | Level 7
Can I do it two steps?

1st step
Copy source file in table format

2nd step
Convert packed filed into numeric
SASKiwi
PROC Star

The safest way is to use a BINARY file transfer from mainframe to ASCII computer, then use S370 INFORMATs on ALL data columns being read in, including text. These transform the EBCDIC data in the file to ASCII format.

Phil20
Obsidian | Level 7

my SAS runs on mainframe. do not have SAS desktop version

Kurt_Bremser
Super User

@Phil20 wrote:

my SAS runs on mainframe. do not have SAS desktop version

So you don't need to copy anything, you just read the file into a SAS dataset (using the aforementioned S370FPD informat for the packed decimals) and then write it back out using textual formats.

Phil20
Obsidian | Level 7

correct.

can you share a sudo code for S370FPD informat

Kurt_Bremser
Super User

What does sudo have to do with this? sudo is a UNIX utility for changing the current user on the fly without knowing the target user password.

The documentation of the S370FPD informat is found here.

Tom
Super User Tom
Super User

Sounds like you don't want to copy the file.

Sounds like you want to read the file into a dataset and then write it back into a new file with a slightly different structure.

Does that sound right?

 

So show the code you would run to read the existing file into a dataset.

Describe the new file you want to create and show the code you would use to convert the dataset into that structure.

 

For example you might have a fixed length file with some packed decimal and other fields and what to create a comma delimited file of pure text.  You could do it without writing any actual SAS dataset by reading and writing in a single data _NULL_ step.

filename in 'orginal file';
filename out 'new file';
data _null_;
  infile in ;
  input field1 $ASCII10. field2 s370pd8. .... ;
  file out dsd ;
  put field1 field2 .... ;
run;
Phil20
Obsidian | Level 7

I want to copy the input file into a new one with reformatted. especially convert ZD fields into readable numeric fields. please see the before and after text files. I opened the same file in file manager with the copybook to show the after look

 

The before look is from 3.4 dataset view.

Tom
Super User Tom
Super User

You seem to be using some type of specialized vocabulary.  I don't know what a "COPYBOOK" is or "a 3.4 dataset view".  I assumed you meant you had documentation on how the file was structured, but you don't seem to have presented that documentation.  You will need to know what is in the file to be able to convert it.

 

If you only want to convert some of the fields you could just read the parts you want to leave alone as text strings.

 

But it will probably work better if actually read the whole file into a SAS dataset. Then you can actually check that you have read it right by doing some quick QC on the values using PROC MEANS or PROC FREQ.

 

Then write the file out in the layout you want.

 

If you need help post example of the actual data lines of the original file. The actual description of what the file contains and a description of the new layout you want to create.

SASKiwi
PROC Star

@Phil20  - Did you read my post? The best way to handle this is to use FTP to copy the file (unchanged) from mainframe to desktop or server using the BINARY option. If you don't use the BINARY option it will scramble your ZD fields so they can't be read easily. 

 

Then you use SAS on your desktop or server with S370 INFORMATs to do the translation. I've done this a lot myself in the past and it works very well.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 13 replies
  • 1704 views
  • 2 likes
  • 4 in conversation