SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
Saravanan
Fluorite | Level 6


Hi,

I`m trying to convert decimal values to character. But i can not preserve the decimal values.

For example, 0.0078 shows up as 0.

Is there anyway i can preserve the exact decimal places after converting to character?

Thanks,

Saravanan

7 REPLIES 7
data_null__
Jade | Level 19

You should supply a bit more information about what you did that did not work, what you have and what you want, that sort of thing.

Saravanan
Fluorite | Level 6

Hi,

This is the dataset.  A is numeric.

A

0.1245

0.0045

0.0235

I need to convert this numeric variable to character. 'A' should be a character in my output.My output should be

A

0.1245

0.0045

0.0235

I tried A1=put(A,$6);

Thanks,

Saravanan

data_null__
Jade | Level 19

You need to use the proper format in the PUT function see post from Anca tilea.

Saravanan
Fluorite | Level 6

Thank you for your assiatance. Much appreciated.

saravanan

AncaTilea
Pyrite | Level 9

This would be one way:

data temp;

length y $10;

     x = 0.03456;

     y = put(x, 10.4);*I arbitrarily selected 4 decimal...which means 10.4 format allows for 10 characters, from which 4 are the decimal part;

run;

Good luck!

Anca.

Saravanan
Fluorite | Level 6

Thank you so much. It works fine.

Saravanan

AncaTilea
Pyrite | Level 9

You are welcome.

Please mark the thread as answered so users don't try to come up with more answers.

Thanks.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 39410 views
  • 5 likes
  • 3 in conversation