## conversion from decimal to characters

Occasional Contributor
Posts: 13

# conversion from decimal to characters

If I use the command put(INSD_N,8.1) and values in column INSD_N are like-

80

120

1390

I get output as

80.0

120.0

1390.0

Is there a command which can give me below result

80.00000

120.0000

1390.000

Posts: 3,069

## Re: conversion from decimal to characters

For the example you have given, format 8.5 works

--
Paige Miller
Posts: 3,852

## Re: conversion from decimal to characters

but you get the pesky w.d format too small message.

data _null_;

input y;
put y bestx8.5;

cards;
80
120
1390
;;;;

run;
80.00000
120.0000
1390.000
Posts: 3,069

## Re: conversion from decimal to characters

```data_null_; wrote:

but you get the pesky w.d format too small message.

```

But if you use BESTX8.5 you get that pesky idea in the back of your head that you shouldn't be using unsupported and undocumented formats ...

--
Paige Miller
Super User
Posts: 8,127

## Re: conversion from decimal to characters

D format works almost as well.

Super Contributor
Posts: 490

## Re: conversion from decimal to characters

If you want to deal with char, you can also use the repeat function for example:

data want ;

y='33.3';

z=length(y);

v=8-z;

x=catt(y,repeat('0',v-1));

run;

Occasional Contributor
Posts: 13

## Re: conversion from decimal to characters

none of the solutions are working

i modified the query - but not getting the expected result for data like '2235042'

select CP_N,

case when INSD_N is not missing

then

put(INSD_N,bestx8.5)

else ' '

end as INSD_N

from CCTRP011_CP

Super Contributor
Posts: 490

## Re: conversion from decimal to characters

How this is not working for you

data have;

input y;

cards;

80

120

1390

2235042

;

run;

data want;

set have;

yy=strip(put(y,8.1));

z= length(yy);

v=8-z;

x=catt(yy,repeat('0',v-1));

run;

Occasional Contributor
Posts: 13

## Re: conversion from decimal to characters

Guys I am not a SAS expert. So some of the suggestions go bouncer for me.

I would appreciate if someone updates my query so that I can understand the exact solution.

rsubmit;
proc sql;
create table TEST_RESULT as
select CP_N,
case when INSD_N is not missing
then put(INSD_N,8.1)
else ' '
end as INSD_N
from CCTRP011_CP

except

select CP_N, INSD_N
from CSTDM111_CUSTOMER
where CUST_DIM not in (0,1,2);
select count(*) from TEST_RESULT;

Super User
Posts: 8,127

## Re: conversion from decimal to characters

This does not appear to have anything to do with this thread. Post it as a new question.

Occasional Contributor
Posts: 13

## Re: conversion from decimal to characters

This is the same question.

Earlier I had given values. Now I am giving the query.

Because I am not able to apply the solution provided in my query.

Super User
Posts: 8,127

## Re: conversion from decimal to characters

So when you convert INSD_N from numeric to character it is still not matching the character strings in the other table?

If the numbers require less than the full 8 characters when converted from number to character with the PUT() function then they will be RIGHT aligned with the PUT() function result.  Usually character variables are LEFT align.  Try wrapping the PUT() function inside of a LEFT() function and see if it helps.

N=5.3

put(N,8.1) -> '     5.3'

Discussion stats
• 11 replies
• 372 views
• 0 likes
• 5 in conversation