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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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