Search code examples
sasproc-format

set missing value with proc format


I'm quite new to SAS and I use the proc format to attribute value to codes :

proc format;
    value code_to_value
        -1 = .
        1 = 0.5
        2 = 0.25
        3 - high = 0;
run;

I then convert it to a numeric column in my dataset.

DATA foo; 
    SET bar;
    my_var = put(my_var ,code_to_value.);
RUN;

The problem is that this code set all -1 code to ., but as a character, not as a missing value.

How can I set it to missing ?


Solution

  • The put() function creates a character value. Combine with input() if you want to convert back to numeric, eg:

    DATA foo; 
      SET bar;
      my_var = input(put(my_var ,code_to_value.),best.);
    RUN;