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:

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

Definition in file