Help using Base SAS procedures

Cobol Compressed Packed Decimal Conversion

Reply
N/A
Posts: 1

Cobol Compressed Packed Decimal Conversion

I'm importing a file from Cobol into SAS and am encountering a problem with two packed decimal fields in the conversion. As the fields are read in, some of the unpacked results read out to the equivalent of hex values 00 or 1A, and therefore my data step thinks it is at the end of a row prematurely. Is there any simple way to either a) simply skip over these fields when reading the file into SAS or b)Tell SAS to disregard the hex equivalents for those fields so each line goes to the full lrecl?
SAS Super FREQ
Posts: 8,868

Re: Cobol Compressed Packed Decimal Conversion

Hi:
My COBOL days are a bit behind me -- several jobs ago, but this note about the correct INFORMATS and how they correspond to COBOL PIC definitions may be useful:
http://support.sas.com/kb/3/714.html

Before you assume that the problem is in the data, I would be sure that you are using the correct INFORMAT on the SAS side to read the data. Here's some more information on reading binary and packed decimal data:
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a003209921.htm

cynthia
Super Contributor
Posts: 474

Re: Cobol Compressed Packed Decimal Conversion

Are you dealing with fixed or variable block files?

Anyway, please share with us the code you are using to import the file.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Super Contributor
Super Contributor
Posts: 3,174

Re: Cobol Compressed Packed Decimal Conversion

Posted in reply to DanielSantos
Also, on what OS are running SAS? What OS does your data originate and how is it created? If the two OS platforms are not the same, how do you transfer (FTP, IND$FILE, and with what parameters) the data from the originating OS platform to the OS platform where you are running SAS to process the data? It would be most useful if you posted a REPLY with the SAS log pasted in it, for others to review -- also with all of your DATA and/or PROC step code revealed.

Scott Barry
SBBWorks, Inc.
Respected Advisor
Posts: 3,799

Re: Cobol Compressed Packed Decimal Conversion

You don't mention OS but I'm thinking Windows, where the default is files that use "control character" to delimit records. This is fine for reading most data but when the data can have any value from 00x to FFx there can be problems. There are two ways in SAS that I know of to ignore record markers. RECFM = N or F. I think you need RECFM=F because you mention records and COBAL and record length. So on the FILENAME statement or the INFILE statement you need RECFM=F and LRECL=. The following example although contrived and cryptic illustrates the difference that these options can make.

[pre]
830 filename FT44F001 temp;
831 data _null_;
832 file FT44F001;
833 do x = '00'x,'1A'x;
834 put 'Hello' x $1.;
835 put x $1. 'hello';
836 end;
837 run;

NOTE: The file FT44F001 is:
File Name=C:\DOCUME~1\userid\LOCALS~1\Temp\SAS Temporary Files\_TD3336\#LN00024,
RECFM=V,LRECL=256

NOTE: 4 records were written to the file FT44F001.
The minimum record length was 6.
The maximum record length was 6.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds


838 Confusion:
839 data _null_;
840 infile FT44F001;
841 input;
842 list;
843 run;

NOTE: The infile FT44F001 is:
File Name=C:\DOCUME~1\userid\LOCALS~1\Temp\SAS Temporary Files\_TD3336\#LN00024,
RECFM=V,LRECL=256

RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

1 CHAR Hello. 6
ZONE 466660
NUMR 85CCF0



RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

2 CHAR .hello 6
ZONE 066666
NUMR 085CCF
3 Hello 5
NOTE: 3 records were read from the infile FT44F001.
The minimum record length was 5.
The maximum record length was 6.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


844 Bliss:
845 data _null_;
846 infile FT44F001 recfm=f lrecl=8;
847 input;
848 list;
849 run;

NOTE: The infile FT44F001 is:
File Name=C:\DOCUME~1\userid\LOCALS~1\Temp\SAS Temporary Files\_TD3336\#LN00024,
RECFM=F,LRECL=8

RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

1 CHAR Hello...
ZONE 46666000
NUMR 85CCF0DA

2 CHAR .hello..
ZONE 06666600
NUMR 085CCFDA

3 CHAR Hello...
ZONE 46666100
NUMR 85CCFADA



RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

4 CHAR .hello..
ZONE 16666600
NUMR A85CCFDA
NOTE: 4 records were read from the infile FT44F001.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds

[/pre]
Ask a Question
Discussion stats
  • 4 replies
  • 532 views
  • 0 likes
  • 5 in conversation