# NAFILL

## Purpose:

Replaces NaN values based on other known data points.

## Syntax:

NAFILL(series, method)

series

-

A series or table.

method

-

An integer. Method used to "fill" NaN values:

 -1: No fill, retain NaN values (hardware based). 0: No fill, retain NaN values (software based). 1: Fill forward using the previous known value. 2: Fill forward, then backward. 3: Fill backward using the next known value. 4: Fill backward, then forward.

## Returns:

A series or table.

## Example:

W1: {2, 5, 7, 9, nan, 13, 15}

W2: nafill(W1, 1)

W3: nafill(W1, 3)

W2 replaces each NaN value with the previous known (i.e. non-nan) value. The new series is {2, 5, 7, 9, 9, 13, 15}.

W3 replaces each NaN value with the next known (i.e. non-nan) value. The new series is {2, 5, 7, 9, 13, 13, 15}.

## Example:

a    = {nan, 2, nan, 4, nan};

naf  = nafill(a, -1);

naf0 = nafill(a, 0);

naf1 = nafill(a, 1);

naf2 = nafill(a, 2);

naf3 = nafill(a, 3);

naf4 = nafill(a, 4);

naf  == {nan, 2, nan, 4, nan}

naf0 == {nan, 2, nan, 4, nan}

naf1 == {nan, 2, 2, 4, 4}

naf2 == {2, 2, 2, 4, 4}

naf3 == {2, 2, 4, 4, nan}

naf4 == {2, 2, 4, 4, 4}

Both naf and naf0 do not replace NaN values.

naf1 fills each NaN value with the previous non-nan value.

naf2 fills each NaN value with the previous non-nan value or if no non-nan value is found, the next non-nan value is used.

naf3 fills each NaN value with the next non-nan value.

naf4 fills each NaN value with the next non-nan value or if no non-nan value is found, the previous non-nan value is used.

## Remarks:

NAFILL replaces NaN values of a series with existing non NaN values.

The method values of -1 and 0 both retain NaN values when encountered in a computation. However, -1 specifies a hardware based NaN detection algorithm where the floating point processor signals the existence of NaN values. Most internal series math computations use the hardware detection method to retain encountered NA values.

Some functions such as MOVAVG default to a method of 2 where NaN values are substituted forward with the last known value or if no value is found, substitute backwards using the next known value. For a long series with many NaN values, this can result in slower processing, but the result will generally not contain NaN values.

The DEFAULT_NA_METHOD configuration parameter in DADISP.CNF specifies the default NaN fill method.

See SETNAVALUE to replace NaN values with a set value.

See REMOVENA to delete NaN values.

READTABLE will read the strings NaN, NA or NULL as NAVALUES.

ISNAN

ISNAVALUE

NAN

NAVALUE

REMOVENA

SETNAVALUE

VALFILL