BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

I want to convert numeric into char.

The problem is that the missing numeric values are converted into '.' and I want to have '' (without period).

I can write a statement  IF C_char='.' then C_char='';

But my question if there is another way to do it?

data have;
input x;
cards;
100
200
.
300
.
600
;
Run;

data want;
set have;
x_char=put(x,best.);
x_char2=put(x,8.-L);
Run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

First, I would try

options missing=" ";

but I can't test in the moment if this also works for PUT functions.

Or you use a custom format:

proc format;
value mybest
  . = " "
  other = [best.]
;
run;

data want;
set have;
x_char=put(x,mybest.);
run;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

First, I would try

options missing=" ";

but I can't test in the moment if this also works for PUT functions.

Or you use a custom format:

proc format;
value mybest
  . = " "
  other = [best.]
;
run;

data want;
set have;
x_char=put(x,mybest.);
run;
PaigeMiller
Diamond | Level 26

The idea of converting numeric to character just so you can change the appearance of a value bothers me. When you want to change the appearance of something, you use a custom format or a built-in SAS format. It seems that this conversion from numeric to character isn't necessary, it's extra work with no apparent benefit. 

 

Using the custom format from @Kurt_Bremser , this works without the unnecessary step of changing from numeric to character:

 

proc print data=have;
    var x;
    format x mybest.;
run;

 

As stated many times already, @Ronein , please test your code before posting it. The code you posted generated errors.

--
Paige Miller
Ronein
Meteorite | Level 14
100%, always better to change the appearance (format) than convert from numeric to char.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 1828 views
  • 3 likes
  • 3 in conversation