Packed decimal format in SAS.

Statistical Analysis System and Cloud Computing.
Previous topicNext topic

Topic Author
H Malik
New Member
Posts: 1
Joined: Fri Feb 13, 2015 7:05 pm

Packed decimal format in SAS.

Post by H Malik » Mon Sep 28, 2015 11:29 am

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: 499
Joined: Sun Aug 25, 2013 7:24 pm

Re: Packed decimal format in SAS.

Post by William Collins » Mon Sep 28, 2015 12:41 pm

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: 874
Joined: Wed Sep 11, 2013 3:57 pm

Re: Packed decimal format in SAS.

Post by enrico-sorichetti » Mon Sep 28, 2015 1:01 pm

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: 499
Joined: Sun Aug 25, 2013 7:24 pm

Re: Packed decimal format in SAS.

Post by William Collins » Mon Sep 28, 2015 2:00 pm

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: 874
Joined: Wed Sep 11, 2013 3:57 pm

Re: Packed decimal format in SAS.

Post by enrico-sorichetti » Mon Sep 28, 2015 4:45 pm

: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: 1331
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
Zodiac: Virgo

Re: Packed decimal format in SAS.

Post by Robert Sample » Wed Sep 30, 2015 6:20 pm

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.



Previous topicNext topic

Return to “SAS & Cloud Computing.”