Packed decimal format in SAS.

Statistical Analysis System and Cloud Computing.
Post Reply
H Malik
New Member
Posts: 1
Joined: Fri Feb 13, 2015 7:05 pm

Packed decimal format in SAS.

Post 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.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Packed decimal format in SAS.

Post 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?
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 826
Joined: Wed Sep 11, 2013 3:57 pm

Re: Packed decimal format in SAS.

Post by enrico-sorichetti »

did You try ARITH(EXTEND)
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Packed decimal format in SAS.

Post 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.
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 826
Joined: Wed Sep 11, 2013 3:57 pm

Re: Packed decimal format in SAS.

Post 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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: Packed decimal format in SAS.

Post 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.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “SAS & Cloud Computing.”