Macros for SAS Application Developers File Reference

Enables previous observations to be re-instated. More...

Go to the source code of this file.

Detailed Description

Remembers the last X observations by storing them in a hash table. Is a convenience over the use of lag() or retain, when an entire observation needs to be restored.

This macro will also restore automatic variables (such as n and error).

Example Usage:

data example;
  set sashelp.class;
  %* initialise hash and save from PDV ;
  if _n_ =10 then do;
    %* fetch previous but 1 record;
    put _n_= name= age= calc_var=;
    %* fetch previous record;
    put _n_= name= age= calc_var=;
    %* reinstate current record ;
    put _n_= name= age= calc_var=;


mp_prevobs sas

Credit is made to data _null_ for authoring this very helpful paper:

actionEither FETCH a current or previous record, or INITialise.
recordThe relative (to current) position of the previous observation to return.
history=The number of records to retain in the hash table. Default=5
prefix=the prefix to give to the variables used to store the hash name and index. Default=mp_prevobs
Allan Bowe

Definition in file