Loading...
Searching...
No Matches
mpe_derived.sas File Reference

Generates the SAS statements that create Data Controller derived variables. More...

Go to the source code of this file.

Detailed Description

Derived (computed) variables are configured in MPE_DERIVED. Each row defines one variable, which is created in a DATA step view ahead of the filter, so that it can be filtered on in the EDIT screen.

The engine lives in @sasjs/core as mp_derivedvars - this macro only supplies what is specific to Data Controller: the control table name, the bitemporal filter that picks the current version of a row, and the list of names that belong to the metadata and may not be used as a variable.

The macro writes the generated statements to a fileref, so that callers can compose them into a view:

%mpe_derived(libds=&libds,dclib=&mpelib,outref=dercode)
data work.vw_derived / view=work.vw_derived;
  set &libds;
  %include dercode;
run;

Alternatively, pass outview= and the macro will build the view itself.

The filter must be applied by the caller, in the step that reads the view:

data out;
  set work.vw_derived;
  where %inc filtref;;
run;

A WHERE statement applies to the data set named on the SET statement, so it cannot reference a variable that is created in the same data step. Applying it to the view puts the derived variables on the input, which is what makes them filterable.

Each statement block is of the form:

attrib REGION length=$21 label='REGION=<expression>' format=$21.;
REGION = <expression>;

Type and length are declared by the administrator, so the result is deterministic. VAR_LABEL is optional: when it is missing or blank the label is the variable name, an equals sign and the expression, otherwise the configured label is used as given.

VAR_DEPS lists every input the expression uses - physical columns and derived variables alike. The statements are generated in dependency order, so a derived variable may build on another one without a sequence number being maintained. A cycle is rejected.

Semicolons, macro triggers and comments are rejected, so a row can only ever be an expression, and an expression that would let the row submit code of its own - DOSUBL, or a function reaching the file system, the environment or the macro symbol table - is refused by name.

The field level rules themselves are core's: mp_derivedvarcheck scans the definitions and mp_derivedvars calls it, which is the same macro the MPE_DERIVED post edit hook runs at submit time (services/hooks/mpe_derived_postedit). A row is therefore measured against one rule list, whether it is being staged or read.

A derived variable may not reuse the name of a physical column, and may not reference itself: an intra-row calculation would imply a retained value, which depends on the order rows happen to arrive in.

SAS Macros

Parameters
[in]libds=The target table (libref.dataset, lib must be assigned)
[in]dclib=The Data Controller control library
[out]outref=(0) Fileref to receive the generated statements
[out]outvars=(work.derived_vars) Dataset of derived variable names
[in]outview=(0) Optional two-level name for the derived view
Version
9.2
Author
4GL Apps Ltd

@sasjslint {"maxLineLength": 89}

Definition in file mpe_derived.sas.