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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.