DATA Step, Macro, Functions and more

Conversion of Numeric to Packed Decimal in using SAS

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Conversion of Numeric to Packed Decimal in using SAS

Hi All,

I am trying to convert a Numeric value to packed decimal value and it is not getting converted. In output fle it is showing as zeros.

Below is my code.

 

 In input file I have a below field defined as Numeric at position 100 and below conversion menthod I used.

 

@100 cnt_Mos_Deln   $03      has value as 006

Cnt_Mos_Ddlpi = INPUT(Cnt_Mos_Deln,??PD3.)

 

in output file, it is defined as,

Cnt_Mos_Ddlpi  PD3.

 

But above code gives zeros(in Hex) in this field.

 

So can I any one please help?


Accepted Solutions
Solution
‎06-20-2017 05:38 PM
Super User
Posts: 6,938

Re: Conversion of Numeric to Packed Decimal in using SAS

You're still using the wrong informat in the input() function.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 3,106

Re: Conversion of Numeric to Packed Decimal in using SAS

Where are you running this code? If it's not being run on a mainframe you will probably need to use S370PD. 

New Contributor
Posts: 4

Re: Conversion of Numeric to Packed Decimal in using SAS

Yes, I am executing code on Mainframe.
Super User
Posts: 6,938

Re: Conversion of Numeric to Packed Decimal in using SAS

Don't use a pd informat in the input function when you have readable data in the string. Use a simple 3. instead.

 

When something unexpected happens, always look at the log.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 4

Re: Conversion of Numeric to Packed Decimal in using SAS

Code:

 

Data Mrtgfinl;
   Infile Mrtgfinl;
   Input @001 nbr_loan_midas $09.
            @273 Cnt_Mos_Deln $03

 

 

 

PUT 'Cnt_Mos_Deln ' Cnt_Mos_Deln= ;
Cnt_mos_ddlpi = INPUT(Cnt_Mos_Deln,??pd3.);
CALL SYMPUT('Cnt_mos_ddlpi ',Cnt_mos_ddlpi);
Put 'Cnt_mos_ddlpi ' Cnt_mos_ddlpi ;

 

 

Output:

Cnt_Mos_Deln Cnt_Mos_Deln=006
Cnt_mos_ddlpi . ,

 

 

 

 

 

Solution
‎06-20-2017 05:38 PM
Super User
Posts: 6,938

Re: Conversion of Numeric to Packed Decimal in using SAS

You're still using the wrong informat in the input() function.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,083

Re: Conversion of Numeric to Packed Decimal in using SAS

I'm not sure whether I can trust the program you are showing, since it is missing at last one semicolon.  But this would definitely be wrong:

 

@100 cnt_Mos_Deln   $03 

 

This gets the value from column 3, not from columns 100-102.  You would have to use a dot instead as part of the informat:  $3.

New Contributor
Posts: 4

Re: Conversion of Numeric to Packed Decimal in using SAS

Below code worked for me

 

Cnt_mos_ddlpi = INPUT(Cnt_Mos_Deln,??3.);

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 128 views
  • 1 like
  • 4 in conversation