Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_init.sas
Go to the documentation of this file.
1
/**
2
@file
3
@brief Initialise session with useful settings and variables
4
@details Implements a "strict" set of SAS options for use in defensive
5
programming. Highly recommended, if you want your code to run on some
6
other machine.
7
8
This macro is recommended to be compiled and invoked in the `initProgram`
9
for SASjs [Jobs](https://cli.sasjs.io/sasjsconfig.html#jobConfig_initProgram
10
), [Services](
11
https://cli.sasjs.io/sasjsconfig.html#serviceConfig_initProgram) and [Tests]
12
(https://cli.sasjs.io/sasjsconfig.html#testConfig_initProgram).
13
14
For non SASjs projects, you could invoke in the autoexec, or in your own
15
solution initialisation macro.
16
17
18
If you have a good idea for another useful option, setting, or global
19
variable - feel free to [raise an issue](
20
https://github.com/sasjs/core/issues/new)!
21
22
All the system variables this macro creates use the hard-coded `_SASJS_`
23
prefix - the same namespace sasjs/server uses in the pre-program it
24
generates for each session (`_SASJS_WEBOUT_HEADERS`, `_SASJS_TOKENFILE`,
25
`_SASJS_USERNAME` ...).
26
27
Setting `_SASJS_INIT` before this macro runs skips it, which is how an
28
autoexec opts out - a second pass would re-apply the options below.
29
30
@version 9.2
31
@author Allan Bowe
32
33
**/
34
35
%macro mp_init(
36
)
/*/STORE SOURCE*/
;
37
38
/* only run once. The guard is the marker: an autoexec that sets it is the
39
documented way to skip this macro, and a second pass would re-apply the
40
options below mid-session. SASJS_PREFIX is the name an existing autoexec
41
would set, so it suppresses initialisation too. */
42
%
if
%symexist(_SASJS_INIT) or %symexist(SASJS_PREFIX) %then %
return
;
43
44
%global
45
_SASJS_INIT
/* set to any value by this macro: "already initialised" */
46
_SASJS_PROCESSMODE
/* process mode, as the server's pre-program names it */
47
_SASJS_WEBOUT_HEADERS
/* the server's webout header file location */
48
_SASJS_FUNCTIONS
/* used in mcf_init() to track core function compilation */
49
_SASJS_INIT_NUM
/* initialisation time as numeric */
50
_SASJS_INIT_DTTM
/* initialisation time in E8601DT26.6 format */
51
_SASJS_WORK
/* avoid typing %sysfunc(pathname(work)) every time */
52
;
53
%let _sasjs_init=1;
54
55
data _null_;
56
dttm=datetime();
57
call symputx(
'_SASJS_INIT_NUM'
,dttm,
'g'
);
58
call symputx(
'_SASJS_INIT_DTTM'
,put(dttm,E8601DT26.6),
'g'
);
59
call symputx(
'_SASJS_WORK'
,pathname(
'WORK'
),
'g'
);
60
run;
61
62
options
63
compress=CHAR
/* default is none so ensure we have something! */
64
datastmtchk=ALLKEYWORDS
/* protection from overwriting input datasets */
65
errorcheck=STRICT
/* catch errs in libname/filename statements */
66
fmterr
/* ensure err when a format cannot be found */
67
mergenoby=%str(ERR)OR
/* throw err when a merge has no BY variables */
68
missing=.
/* changing this can cause hard to detect errs */
69
noquotelenmax
/* avoid warnings for long strings */
70
noreplace
/* avoid overwriting permanent datasets */
71
ps=max
/* reduce log size slightly */
72
ls=max
/* reduce log even more and avoid word truncation */
73
validmemname=COMPATIBLE
/* avoid special characters etc in table names */
74
validvarname=V7
/* avoid special characters etc in variable names */
75
varinitchk=%str(ERR)OR
/* avoid data mistakes from variable name typos */
76
varlenchk=%str(ERR)OR
/* fail hard if truncation (data loss) can result */
77
%
if
"%substr(&sysver,1,1)"
ne
"4"
and
"%substr(&sysver,1,1)"
ne
"5"
%then %
do
;
78
noautocorrect
/* disallow misspelled procedure names */
79
dsoptions=note2err
/* undocumented - convert bad NOTEs to ERRs */
80
/* turn off with dsoptions=nonote2err */
81
%end;
82
;
83
84
%mend mp_init;
base
mp_init.sas
Generated by
1.15.0
For more information visit the
Macro Core library
.