- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all --
I have a binary file with packed data I'm trying to import. I was given this layout below and I'm not exactly sure what formats I can use to map to the COBOL pictures listed below to SAS formats, especially the date formats. Apologies for being vague but I have no experience with files like this.
Location | Length | Cobol Picture | Cobol Field Name |
1-1 | 1 | X(001) | FIELD1 |
2-3 | 2 | X(002) | FIELD2 |
4-4 | 1 | X(001) | FIELD3 |
5-10 | 6 | X(006) | FIELD4 |
11-11 | 1 | X(001) | FIELD5 |
12-14 | 3 | X(003) | FIELD6 |
15-16 | 2 | S9(003) C3 | FIELD7 |
17-170 | 154 | X(154) | FIELD8 |
171-171 | 1 | X(001) | FIELD9 |
172-173 | 2 | X(002) | FIELD10 |
174-175 | 2 | X(002) | FIELD11 |
176-177 | 2 | X(002) | FIELD12 |
178-179 | 2 | X(002) | FIELD13 |
180-181 | 2 | X(002) | FIELD14 |
182-184 | 3 | X(003) | FIELD15 |
185-191 | 7 | X(007) | FIELD16 |
192-192 | 1 | X(001) | FIELD17 |
193-195 | 3 | S9(005) C3 | FIELD18 |
196-200 | 5 | S9(007)V99 C3 | FIELD19 |
201-204 | 4 | S9(007) C3 |
FIELD20_DATE |
Example code I'm using -- the issue is I'm just getting a bunch of blank/null values upon running. Perhaps I have some of the formats incorrect on the fields that contain packed data? Any ideas?
data work.test;
infile "&file" truncover lrecl=1800;
input
@1 field1 $char1.
@2 field2 $char2.
@4 field3 $char1.
@5 field4 $char6.
@11 field5 $char1.
@12 field6 $char3.
@15 field7 s370fpd2.
.
.
.
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You probably need to use RECFM=F and a LRECL= value that matches the record length.
infile "&file" lrecl=204 recfm=f;
Take a look at the beginning of the file to see what is in it. For example this will dump the first 3*204 bytes of the file to the log. Any non-ASCII characters will probably trigger the LIST command to print the hexadecimal representation of each byte.
data _null_;
infile "&file" lrecl=204 recfm=f obs=3;
input;
list;
run;
Make sure the file hasn't been moved from the mainframe as if it was a text file instead of binary file. That can mess up the bytes in the file in ways that cannot be recovered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This very useful SAS Note should help: https://support.sas.com/kb/56/654.html
I assume you are trying to read this using SAS on a non-mainframe system, that is an ASCII system. If so you will need to use the $EBDCDIC INFORMAT for character data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For S9(003) C3, your Comp-3 (I assume that's what C3 means), i.e. packed decimal data can have three digits followed by a sign ('123F'x), therefore I would use S370FPD2, which is just what you're using. As others have indicated, you want to make sure the data is transferred off the mainframe in binary mode. If it is transferred in default mode (which could be ASCII), then the transfer process will try to translate anything it "recognizes" from EBCDIC to ASCII which you don't want. You want the numbers to come through unchanged so that they can be properly interpreted by the S370 series formats.
I believe field 18 should be S370FPD2,
I believe field 19 should be S370FPD5,
I believe field 19 should be S370FPD4,
All of the character fields would just use a format of $EBCDICx. where "X" is the length in your COBOL layout. e.g. PIC X(007) becomes $EBCDIC7.
What's up with that LRECL=1800? Your layout only goes to position 204. Are you sure you want LRECL=1800? Have you tried LRECL=204? If you haven't tried it, I would try two things:
1. Try running with LRECL=204
2. Try changing TRUNCOVER to MISSOVER and re-running. I seem to recall getting better results with fixed position files with MISSOVER.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content