Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_derivedvarcheck.sas File Reference

Validates derived variable definitions, one row per rule. More...

Go to the source code of this file.

Detailed Description

Reads a table of derived variable definitions and writes one row per definition that breaks a rule, with the reason in REASON. Nothing is executed, no view is built and no target table is needed: the macro is a scan of definitions, so it can run at submit time - or against any table of expressions in a code scanning tool - long before the definitions are used.

The input is the shape a control table carries, which is the shape mddl_derivedvars.sas creates:

  • VAR_NM - the name of the variable to create
  • VAR_TYPE - C or N
  • VAR_LEN - a positive integer, at most 32767 for character and 8 for numeric
  • VAR_FMT - an optional format name
  • VAR_LOGIC - the expression, which must be a single expression with no macro triggers and no comments, at most 4000 characters - the limit of the statement buffer and of the control table, so a longer value would be cut down silently
  • VAR_LABEL - optional, plain text of at most 256 characters. A line break is allowed and becomes a space when the label is used

Extra columns are ignored, so a caller can scan the control table itself, a staged submission, or a table of expressions assembled from a program.

Why a function name is refused and a character is not

VAR_LOGIC is concatenated into a generated assignment, so an expression that can submit a program of its own (DOSUBL) or reach the file system, the environment or the macro symbol table is a way into the session. Blocked characters cannot cover that: BYTE(59) builds the semicolon at run time, so a payload carries no blocked character in its source text - while the name of the function it calls is part of the expression this scan reads, and cannot be constructed. Quoted literals are removed before the check, so a refused word that is only data is not read as a call.

The refused names are DOSUBL, JAVAOBJ, JAVAMETA, SYMGET, SYMPUT, SYMPUTX, SYSGET, GETOPTION, PATHNAME, FILEEXIST, FOPEN, FREAD, FGET, FCLOSE, DOPEN, DREAD, DNUM, MOPEN, SLEEP, FILENAME, FDELETE, FCOPY, DCREATE and DLCREATE. Add your own with denyfuncs=.

SAS Macros

Related Macros

Parameters
[in]inds=The definitions to check
[out]outds=(work.dv_check) One row per definition that breaks a rule: NAME (the upcased VAR_NM) and REASON. Empty when every row is valid
[in]physlist=(0) Space separated list of the columns of the target table, unquoted and case insensitive - what mf_getvarlist(&libds) returns. Supplied, a VAR_NM that collides with one of them is refused; when the target is not at hand, leave it at 0 and that rule is not applied
[in]reserved=(0) Space separated list of names that may not be used
[in]denyfuncs=(0) Space separated list of further function names to refuse, for a site that allows more of the SAS vocabulary than the default. Each entry must be a function name - letters, digits and underscores - so the pattern the check builds stays a pattern of names
Version
1.0
Author
4GL Apps Ltd

Definition in file mp_derivedvarcheck.sas.