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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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