## convert numeric variable missing values to character variable missing values

Solved
Frequent Contributor
Posts: 146

# convert numeric variable missing values to character variable missing values

Hi,

I used an array to convert the numeric variables  to character variables. None of the numeric variables had any formats associated with it but all had a length of 8. The value for non-missing numeric values was 1 and the value of missing numeric values was a period. I applied the character fomat \$40. as I need to reformat the values later. However, after conversion of the numeric to character the missing values are being retained as periods and not blanks. Is there a way to have them as blanks after the conversion? Please let me know as soon as possible. Thanks.

Array _numeric(*)

var2

var3

var4

var5

var6;

Array _character(*) \$ 40

var2_C

var3_C

var4_C

var5_C

var6_C

DO i=1 to dim(_numeric);

_character(i) = PUT(_numeric(i),8.);

END;

Accepted Solutions
Solution
‎05-15-2017 01:54 AM
Super User
Posts: 6,785

## Re: convert numeric variable missing values to character variable missing values

A simple change to one statement:

if _numeric(i) > . then _character(i) = PUT(_numeric(i),8.);

All Replies
Solution
‎05-15-2017 01:54 AM
Super User
Posts: 6,785

## Re: convert numeric variable missing values to character variable missing values

A simple change to one statement:

if _numeric(i) > . then _character(i) = PUT(_numeric(i),8.);

Posts: 3,167

## Re: convert numeric variable missing values to character variable missing values

@Astounding, chance is very slim, yet possible:

``````data test;
input num;
char=put(num,8.);
char_1=ifc(num>.,put(num,8.),'');
char_2=ifc(not missing(num),put(num,8.),'');
cards;
100
.
._
.A
.Z
;``````
Super User
Posts: 8,124

## Re: convert numeric variable missing values to character variable missing values

[ Edited ]

You can change the setting of the MISSING option.  Also be careful how you convert to character. Your current use of the PUT() function will cause your character variables to have leading spaces.

```2183  %let save=%sysfunc(quote(%qsysfunc(getoption(missing))));
2184  options missing=' ';
2185  data _null_;
2186    do x=0,1,.,123.456 ;
2187      c1=put(x,8.);
2188      c2=cats(x);
2189      put x= (c1 c2) (= :\$quote.) ;
2190    end;
2191  run;

x=0 c1="       0" c2="0"
x=1 c1="       1" c2="1"
x= c1="" c2=""
x=123.456 c1="     123" c2="123.456"
NOTE: DATA statement used (Total process time):
real time           0.00 seconds
cpu time            0.00 seconds

2192  options missing=&save;```

☑ This topic is solved.