BookmarkSubscribeRSS Feed
nikhilbajaj
Calcite | Level 5

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

11 REPLIES 11
PaigeMiller
Diamond | Level 26

For the example you have given, format 8.5 works

--
Paige Miller
data_null__
Jade | Level 19

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
PaigeMiller
Diamond | Level 26

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
Tom
Super User Tom
Super User

D format works almost as well.

mohamed_zaki
Barite | Level 11

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;

nikhilbajaj
Calcite | Level 5

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

mohamed_zaki
Barite | Level 11

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;

nikhilbajaj
Calcite | Level 5

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;

Tom
Super User Tom
Super User

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

nikhilbajaj
Calcite | Level 5

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.

Tom
Super User Tom
Super User

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'

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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