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 global variables are prefixed with "SASJS" (unless modified with the
23 prefix parameter).
24
25 @param [in] prefix= (SASJS) The prefix to apply to the global macro variables
26
27
28 @version 9.2
29 @author Allan Bowe
30
31**/
32
33%macro mp_init(prefix=SASJS
34)/*/STORE SOURCE*/;
35
36%if %symexist(SASJS_PREFIX) %then %return; /* only run once */
37
38%global
39 SASJS_PREFIX /* the ONLY hard-coded global macro variable in SASjs */
40 &prefix._FUNCTIONS /* used in mcf_init() to track core function compilation */
41 &prefix._INIT_NUM /* initialisation time as numeric */
42 &prefix._INIT_DTTM /* initialisation time in E8601DT26.6 format */
43 &prefix.WORK /* avoid typing %sysfunc(pathname(work)) every time */
44;
45
46%let sasjs_prefix=&prefix;
47
48data _null_;
49 dttm=datetime();
50 call symputx("&sasjs_prefix._init_num",dttm,'g');
51 call symputx("&sasjs_prefix._init_dttm",put(dttm,E8601DT26.6),'g');
52 call symputx("&sasjs_prefix.work",pathname('WORK'),'g');
53run;
54
55options
56 compress=CHAR /* default is none so ensure we have something! */
57 datastmtchk=ALLKEYWORDS /* protection from overwriting input datasets */
58 errorcheck=STRICT /* catch errs in libname/filename statements */
59 fmterr /* ensure err when a format cannot be found */
60 mergenoby=%str(ERR)OR /* throw err when a merge has no BY variables */
61 missing=. /* changing this can cause hard to detect errs */
62 noquotelenmax /* avoid warnings for long strings */
63 noreplace /* avoid overwriting permanent datasets */
64 ps=max /* reduce log size slightly */
65 ls=max /* reduce log even more and avoid word truncation */
66 validmemname=COMPATIBLE /* avoid special characters etc in table names */
67 validvarname=V7 /* avoid special characters etc in variable names */
68 varinitchk=%str(ERR)OR /* avoid data mistakes from variable name typos */
69 varlenchk=%str(ERR)OR /* fail hard if truncation (data loss) can result */
70%if "%substr(&sysver,1,1)" ne "4" and "%substr(&sysver,1,1)" ne "5" %then %do;
71 noautocorrect /* disallow misspelled procedure names */
72 dsoptions=note2err /* undocumented - convert bad NOTEs to ERRs */
73%end;
74;
75
76%mend mp_init;