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.
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!
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.