LAST_NONBLANK: Retrieving the Last Field Value That is Neither Blank nor Missing

How to:

LAST_NONBLANK retrieves the last field value that is neither blank nor missing. If all previous values are either blank or missing, LAST_NONBLANK returns a missing value.

Syntax: How to Return the Last Value That is Neither Blank nor Missing

LAST_NONBLANK(field)

where:

field

Is the field name whose last non-blank value is to be retrieved. If the current value is not blank or missing, the current value is returned.

Note: LAST_NONBLANK cannot be used in a compound expression, for example, as part of an IF condition.

Example: Retrieving the Last Non-Blank Value

Consider the following delimited file named input1.csv that has two fields named FIELD_1 and FIELD_2.

,
A,
,
 ,
B,
C,

The input1 Master File follows.

FILENAME=INPUT1, SUFFIX=DFIX    ,
 DATASET=baseapp/input1.csv(LRECL 15 RECFM V, BV_NAMESPACE=OFF, $
  SEGMENT=INPUT1, SEGTYPE=S0, $
    FIELDNAME=FIELD_1, ALIAS=E01, USAGE=A1V, ACTUAL=A1V,
      MISSING=ON, $
    FIELDNAME=FIELD_2, ALIAS=E02, USAGE=A1V, ACTUAL=A1V,
      MISSING=ON, $

The input1 Access File follows.

SEGNAME=INPUT1, 
  DELIMITER=',', 
  HEADER=NO, 
  PRESERVESPACE=NO, 
  CDN=COMMAS_DOT, 
  CONNECTION=<local>, $

The following request displays the FIELD_1 values and computes the last non-blank value for each FIELD_1 value.

TABLE FILE baseapp/INPUT1
PRINT FIELD_1 AS Input 
COMPUTE
Last_NonBlank/A1 MISSING ON = LAST_NONBLANK(FIELD_1);
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END

The output is shown in the following image.