DATA Step, Macro, Functions and more

How to read packed decimal correctly in the zOS environment

Reply
New Contributor HK1
New Contributor
Posts: 2

How to read packed decimal correctly in the zOS environment

 

Can you let me know how to read in packed decimal data correctly. I have tried two different formats and it is not listing last digit correctly:

 

 

DATA _NULL_;                         

                                       

  ACCTI = '0123456789001234567C'X;  

  

  ACCTO = INPUT(ACCTI, PD10.);      

  PUT '1 ' ACCTI= HEX. ACCTO= 20.;   

                                

  ACCTO = INPUT(ACCTI,7 S370FPD10.); 

  PUT '2 ' ACCTI= HEX. ACCTO= 20.;   

                                       

RUN;   

The following is the info from SYSOUT

                                                                                         

1 ACCTI=0123456789001234567C ACCTO=123456789001234560

                                                     

2 ACCTI=0123456789001234567C ACCTO=123456789001234560

 

Thanks

Trusted Advisor
Posts: 1,553

Re: How to read packed decimal correctly in the zOS environment

To read PD you need use informat  S370FPDw.   where w is the length in bytes:

 

6 bytes enable 11 digits and a sign - should be read by: input var s370fpd6.

New Contributor HK1
New Contributor
Posts: 2

Re: How to read packed decimal correctly in the zOS environment

Thanks for the info. Here I am trying to read max 18 digits and there is C at the end. Thought in the scenario we will need PD10?
Trusted Advisor
Posts: 1,553

Re: How to read packed decimal correctly in the zOS environment

That's right - s370fpd10.
Super User
Posts: 7,760

Re: How to read packed decimal correctly in the zOS environment


HK1 wrote:
Thanks for the info. Here I am trying to read max 18 digits and there is C at the end. Thought in the scenario we will need PD10?

Usually, dec_fixed numbers are defined in PL/1 with an uneven number of digits, as you will need 10 bytes for 18 or 19 digits anyway, so the programmer takes the larger digit count.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 4 replies
  • 194 views
  • 0 likes
  • 3 in conversation