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?
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.);
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.);
Thank you!
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=".";
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.