Solved
New Contributor
Posts: 4

# 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.

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

## Re: Conversion of Numeric to Packed Decimal in using SAS

Posted in reply to durgesh101

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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

All Replies
Super User
Posts: 4,025

## Re: Conversion of Numeric to Packed Decimal in using SAS

Posted in reply to durgesh101

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: 10,574

## Re: Conversion of Numeric to Packed Decimal in using SAS

Posted in reply to durgesh101

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
How to convert datasets to data steps
How to post code
New Contributor
Posts: 4

## Re: Conversion of Numeric to Packed Decimal in using SAS

Posted in reply to KurtBremser

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: 10,574

## Re: Conversion of Numeric to Packed Decimal in using SAS

Posted in reply to durgesh101

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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 6,934

## Re: Conversion of Numeric to Packed Decimal in using SAS

Posted in reply to durgesh101

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

Posted in reply to Astounding

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
• 465 views
• 1 like
• 4 in conversation