-2

I am trying to set missing values to NULL in SAS dataset for a numerical variable, how can I do this?

as missing is null in sas?

user3658367
  • 641
  • 1
  • 14
  • 30
  • Possible duplicate of [Difference between MISSING and NULL in SAS](http://stackoverflow.com/questions/33922842/difference-between-missing-and-null-in-sas) – Sean Nov 29 '16 at 13:59
  • If you're not asking about displaying it, then it's probably a duplicate, but it's unclear to me. – Joe Nov 29 '16 at 19:35

3 Answers3

1

If you're asking how to have the period not display for a missing value, you can use:

options missing=' ';

That however doesn't actually change them to null, but rather to space. SAS must have some character to display for missing, it won't allow no character. You could also pick another character, like:

options missing=%sysfunc(byte(255));

or even

options missing="%sysfunc(byte(0))";

I don't recommend the latter, because it causes some problems when SAS tries to display it.

You can then trim out the space (using trimn() which allows zero length strings) if you are concatenating it somewhere.

Joe
  • 62,789
  • 6
  • 49
  • 67
0

Taking the question very literally, and assuming that you want to display the string NULL for any missing values - one approach is to define a custom format and use that:

proc format;
  value nnull
  .a-.z = 'NULL'
  .     = 'NULL'
  ._    = 'NULL'
  ;
run;

data _null_;
  do i = .a,., ._, 1,1.11;
    put i nnull.;
  end; 
run;
user667489
  • 9,501
  • 2
  • 24
  • 35
0

You can set values to missing within a data step, when it is numeric :

age=.;

to check for missing numeric values use :

if numvar=. then do;

or use MISSING function :

if missing(var) then do;

IS NULL and IS MISSING are used in the WHERE clause. Look at : http://www.sascommunity.org/wiki/Tips:Use_IS_MISSING_and_IS_NULL_with_Numeric_or_Character_Variables

D. O.
  • 616
  • 1
  • 11
  • 25