BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BalajiBollu
Obsidian | Level 7

I have a numeric variable and it has some missing values (represented as '.')... I want to convert it as a character variable with a length 1. But i don't want '.' to be converted as '.' itself instead i need it to be a space (missing notation for character variable). How to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Since the character variable will be initialized to blank anyway, you need only make the put() conditional:

if numvar ne . then charvar = put(numvar,1.);

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

Since the character variable will be initialized to blank anyway, you need only make the put() conditional:

if numvar ne . then charvar = put(numvar,1.);
BalajiBollu
Obsidian | Level 7

Thank you!

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Another useful method - if you have to do lots of these, is to set options missing before and after the code:

options missing="";

...your code...

options missing=".";
ballardw
Super User

A third option is to use a custom format. Example

proc format ;
value myvalue
low-high=[best8.]
other=' '
;
run;

Using the above format would display all non-missing values using the best8. SAS format, any other format could be used inside the [ ] and other values as a blank. This approach has the advantage of allowing you to display more characters without changing any variable lengths that a character value would but will appear in the output. Changing the format to, or creating a different format that is similar, to:

 

proc format ;
value myvalue
low-high=[best8.]
other='Not Recorded'
;
run;

would display "Not Recorded" or perhaps other more meaningful text in output for the missing values.

 

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
  • 4 replies
  • 984 views
  • 4 likes
  • 4 in conversation