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

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
Onyx | Level 15
100%, always better to change the appearance (format) than convert from numeric to char.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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