Page 1 of 1

Packed decimal format in SAS.

Posted: Mon Sep 28, 2015 11:29 am
by H Malik
Hello,

In a COBOL program one variable is defined as S9(18 ) COMP-3. Ineed to write it in a SAS dataset. In SAS, it is defined as EMP_ID PD10. Now, I want to verify the data in the SAS dataset. The sas field is written to output file but the output does not come correctly if the field has 18 digits or more. For example, if the i/p value is 225346343636363636(18 digits) the o/p is 225346343636363632. But if the input is of 17 digits it shows correctly.

SAS code is:

Code: Select all

DATA _NULL_; 
SET OUTFILE(KEEP=EMP_ID); 
FILE OUTFIL2; 
PUT @1 EMP_ID 20.; 
RUN; 
Could you please help me.

Re: Packed decimal format in SAS.

Posted: Mon Sep 28, 2015 12:41 pm
by William Collins
What have you got that can have 18 digits? An Employee ID? Packed? Why? Why have you got the 20.? What verification do you want to do?

Re: Packed decimal format in SAS.

Posted: Mon Sep 28, 2015 1:01 pm
by enrico-sorichetti
did You try ARITH(EXTEND)

Re: Packed decimal format in SAS.

Posted: Mon Sep 28, 2015 2:00 pm
by William Collins
enrico,

ARITH(EXTEND) is a COBOL thing, and SAS has no equivalent. A reliable source (who will be along later) has previously indicated that SAS does not have an equivalent.

H Malik,

If all 18 digits are actually used. the field would need to be split into two and each part dealt with separately. SAS has a BCD data-type (PK) which can be used for the first part (which will not contain a sign) and a PD for the actual packed-decimal remaining part.

Or store the number as an unsigned Zoned Decimal, and treat it as character ($CHAR10).

Not that although some 17-digit values will be displayed correctly, not all 17-digit value will be displayed correctly. Try anything starting with 73 or higher.

Re: Packed decimal format in SAS.

Posted: Mon Sep 28, 2015 4:45 pm
by enrico-sorichetti
:oops:
from the wording I had thought it was a cobol problem
In a COBOL program one variable is defined as S9(18 ) COMP-3. Ineed to write it in a SAS dataset.
the variable content written out wrong

Re: Packed decimal format in SAS.

Posted: Wed Sep 30, 2015 6:20 pm
by Robert Sample
SAS does not handle numbers the same as COBOL. With SAS, the largest integer for which you are guaranteed full accuracy is 9,007,199,254,740,992. If your requirement is for 17 or 18 digits, you will have to either use multiple SAS variables for the value or not use SAS at all. You will not be able to use the entire value as a single variable.