@sasjs/core 5.0.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  [![npm package](https://img.shields.io/npm/v/@sasjs/core.svg)](http://npmjs.org/package/@sasjs/core)
4
4
  [![Github Workflow](https://github.com/sasjs/core/actions/workflows/main.yml/badge.svg)](https://github.com/sasjs/core/blob/main/.github/workflows/main.yml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/sasjs/core/blob/main/LICENSE)
6
+ [![npms.io](https://img.shields.io/npms-io/final-score/@sasjs/core)](https://npms.io/search?q=%40sasjs%2Fcore)
5
7
  ![npm](https://img.shields.io/npm/dt/@sasjs/core)
6
- ![GitHub top language](https://img.shields.io/github/languages/top/sasjs/core)
7
- [![GitHub closed issues](https://img.shields.io/github/issues-closed-raw/sasjs/core)](https://github.com/sasjs/core/issues?q=is%3Aissue+is%3Aclosed)
8
+ ![GitHub last commit](https://img.shields.io/github/last-commit/sasjs/core)
8
9
 
9
10
 
10
11
  Much quality. Many standards. The **Macro Core** library exists to save time and development effort! Herein ye shall find a veritable host of MIT-licenced, production quality SAS macros. These are a mix of tools, utilities, functions and code generators that are useful in the context of [Application Development](https://sasapps.io) on the SAS platform (eg https://datacontroller.io). [Contributions](https://github.com/sasjs/core/blob/main/.github/CONTRIBUTING.md) are welcome.
@@ -227,7 +228,7 @@ We are currently on major release v5. The following breaking changes were appli
227
228
  * mp_abort.sas - the redundant type= parameter was removed.
228
229
  * mp_coretable.sas - removed, and replaced by the standalone macros in the `ddl` folder
229
230
  * mp_getddl.sas - renamed to mp_ds2ddl.sas (consistent with other ds2xxx macros). The default for SHOWLOG is now YES instead of NO.
230
- * mp_testservice.sas - renamed to mp_execute.sas (as it doesn't actually test anything)
231
+ * mp_testservice.sas - renamed to mx_execute.sas (as it doesn't actually test anything, and the mp_ suite should not reference mx_ macros)
231
232
 
232
233
  ## Star Gazing
233
234
 
@@ -41,7 +41,7 @@
41
41
  @li LABEL - Use the variable label (or name, if blank)
42
42
  @li NAME - Use the variable name
43
43
  @li SASJS - Used to create sasjs-formatted input CSVs, eg for use in
44
- mp_execute.sas. This format will supply an input statement in the
44
+ mx_execute.sas. This format will supply an input statement in the
45
45
  first row, making ingestion by datastep a breeze. Special misisng values
46
46
  will be prefixed with a period (eg `.A`) to enable ingestion on both SAS 9
47
47
  and Viya. Dates / Datetimes etc are identified by the format type (lookup
@@ -28,6 +28,9 @@
28
28
  @param [in] rule The rule to apply. Current rules:
29
29
  @li ISINT - checks if the variable is an integer
30
30
  @li ISLIB - checks if the value is a valid libref (NOT whether it exists)
31
+ @li ISNAME - checks if the value is a valid SAS NAME (V7 rules - up to 32
32
+ chars, starting with a letter or underscore, followed by letters,
33
+ numbers or underscores)
31
34
  @li ISNUM - checks if the variable is numeric
32
35
  @li LIBDS - matches LIBREF.DATASET format
33
36
  @li FORMAT - checks if the provided format is syntactically valid
@@ -79,6 +82,20 @@
79
82
  if prxmatch(&tempcol, trim(&incol)) then &outcol=1;
80
83
  else &outcol=0;
81
84
  %end;
85
+ %else %if &rule=ISNAME %then %do;
86
+ /* match a valid SAS name (V7 rules) */
87
+ if _n_=1 then do;
88
+ retain &tempcol;
89
+ &tempcol=prxparse('/^[_a-z]\w{0,31}$/i');
90
+ if missing(&tempcol) then do;
91
+ putlog 'ERR' +(-1) "OR: Invalid expression for ISNAME";
92
+ stop;
93
+ end;
94
+ drop &tempcol;
95
+ end;
96
+ if prxmatch(&tempcol, trim(&incol)) then &outcol=1;
97
+ else &outcol=0;
98
+ %end;
82
99
  %else %if &rule=LIBDS %then %do;
83
100
  /* match libref.dataset */
84
101
  if _n_=1 then do;
package/package.json CHANGED
@@ -1,11 +1,18 @@
1
1
  {
2
2
  "name": "@sasjs/core",
3
- "description": "Macros for SAS Application Developers",
3
+ "description": "Production-quality MIT-licensed SAS macro library (mf_*, mp_*, mm* macros) for SAS 9 and Viya application development",
4
4
  "license": "MIT",
5
5
  "keywords": [
6
6
  "SAS",
7
7
  "Viya",
8
- "SASjs"
8
+ "SASjs",
9
+ "sas-macros",
10
+ "sas-macro-library",
11
+ "sas9",
12
+ "sas-viya",
13
+ "datastep",
14
+ "etl",
15
+ "sasjs-cli"
9
16
  ],
10
17
  "author": "Allan Bowe",
11
18
  "repository": {
@@ -24,7 +31,6 @@
24
31
  "url": "https://github.com/sasjs/core/issues"
25
32
  },
26
33
  "homepage": "https://core.sasjs.io",
27
- "main": "index.js",
28
34
  "scripts": {
29
35
  "build": "npx @sasjs/cli cbd -t server",
30
36
  "docs": "npx @sasjs/cli doc -t docsonly && ./sasjs/utils/build.sh",
@@ -35,5 +41,5 @@
35
41
  "maintainers": [
36
42
  "https://sasapps.io"
37
43
  ],
38
- "version": "5.0.0"
44
+ "version": "5.2.0"
39
45
  }
@@ -42,7 +42,7 @@
42
42
  @li ms_runstp.sas
43
43
 
44
44
  <h4> Related Programs </h4>
45
- @li mp_execute.sas
45
+ @li mx_execute.sas
46
46
 
47
47
  @version 9.4
48
48
  @author Allan Bowe
@@ -0,0 +1,127 @@
1
+ /**
2
+ @file
3
+ @brief Creates a file in the logical filesystem of the target platform
4
+ @details When building applications that run on multiple flavours of SAS, it
5
+ is convenient to use a single macro (like this one) to write a text file -
6
+ eg a settings file - without worrying about the platform primitive.
7
+
8
+ The file is created in the logical filesystem of the target platform (SAS
9
+ Content folder, SASjs Drive, or metadata folder). No file is created on a
10
+ physical filesystem. Platform behaviour:
11
+ - SASVIYA: creates a SAS Content file (%mv_createfile)
12
+ - SASJS: creates a file on SASjs Drive (%ms_createfile)
13
+ - SAS 9 / metadata: SAS 9 has no "file" concept for Stored Process content,
14
+ so a type 2 Stored Process is created in metadata (%mm_createstp), with
15
+ the content loaded as the STP source code
16
+
17
+ The alternative would be to compile a generic macro in target-specific
18
+ folders (SASVIYA, SAS9 and SASJS). This avoids compiling unnecessary macros
19
+ at the expense of a more complex sasjsconfig.json setup.
20
+
21
+ Usage:
22
+
23
+ filename ft15f001 temp;
24
+ data _null_;
25
+ file ft15f001;
26
+ put '%let mysetting=42;';
27
+ run;
28
+
29
+ %* viya: /Public/app/myapp/settings (Files Service) ;
30
+ %* sasjs: /Public/app/myapp/settings.sas (SASjs Drive) ;
31
+ %* sas9: /User Folders/sasdemo/myapp/settings (metadata) ;
32
+ %let filepath=/Public/app/myapp/settings;
33
+ %mx_createfile(&filepath, inref=ft15f001)
34
+
35
+ @param [in] filepath The full path of the file to create, INCLUDING the
36
+ filename (must contain at least one `/` delimiter). On SASjs Server the
37
+ name should carry the .sas extension if it will be executed as a Stored
38
+ Program.
39
+ @param [in] inref= (0) The fileref containing the file content. A valid
40
+ fileref is mandatory - if omitted, the macro aborts with an error.
41
+ @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
42
+
43
+ <h4> SAS Macros </h4>
44
+ @li mf_getplatform.sas
45
+ @li mf_getuniquefileref.sas
46
+ @li mm_createstp.sas
47
+ @li ms_createfile.sas
48
+ @li mv_createfile.sas
49
+
50
+ <h4> Related Macros </h4>
51
+ @li mx_createwebservice.sas
52
+ @li mx_getcode.sas
53
+
54
+ **/
55
+
56
+ %macro mx_createfile(filepath
57
+ ,inref=0
58
+ ,mdebug=0
59
+ )/*/STORE SOURCE*/;
60
+
61
+ %local platform name shortloc;
62
+ %let platform=%mf_getplatform();
63
+
64
+ %if &inref=0 %then %do;
65
+ %put %str(ERR)OR: &sysmacroname requires a valid inref fileref;
66
+ %return;
67
+ %end;
68
+
69
+ %if &platform=SASJS %then %do;
70
+ %ms_createfile(%superq(filepath), inref=&inref, mdebug=&mdebug)
71
+ %end;
72
+ %else %if &platform=SASVIYA %then %do;
73
+ /* extract name & path from &filepath */
74
+ data _null_;
75
+ filepath=symget('filepath');
76
+ name=scan(filepath,-1,'/');
77
+ shortloc=substr(filepath,1,length(filepath)-length(name)-1);
78
+ call symputx('name',name,'l');
79
+ call symputx('shortloc',shortloc,'l');
80
+ run;
81
+ %mv_createfile(path=%superq(shortloc)
82
+ ,name=%superq(name)
83
+ ,inref=&inref
84
+ ,mdebug=&mdebug
85
+ )
86
+ %end;
87
+ %else %if &platform=SAS9 or &platform=SASMETA %then %do;
88
+ /* no file concept - create a type 2 STP (source code saved in metadata).
89
+ The mm_createstp macro requires a physical file, so copy the inref
90
+ content to WORK first. It then loads the source code, meaning no
91
+ separate mm_updatestpsourcecode call is needed. */
92
+ data _null_;
93
+ filepath=symget('filepath');
94
+ name=scan(filepath,-1,'/');
95
+ shortloc=substr(filepath,1,length(filepath)-length(name)-1);
96
+ call symputx('name',name,'l');
97
+ call symputx('shortloc',shortloc,'l');
98
+ run;
99
+ %local fref;
100
+ %let fref=%mf_getuniquefileref();
101
+ filename &fref "%sysfunc(getoption(work))/%superq(name).sas";
102
+ data _null_;
103
+ infile &inref lrecl=32767;
104
+ file &fref lrecl=32767;
105
+ input;
106
+ put _infile_;
107
+ run;
108
+ %mm_createstp(stpname=%superq(name)
109
+ ,tree=%superq(shortloc)
110
+ ,filename=%superq(name).sas
111
+ ,directory=%sysfunc(getoption(work))
112
+ ,stptype=2
113
+ ,mdebug=&mdebug
114
+ )
115
+ %if &mdebug=0 %then %do;
116
+ /* remove the temporary physical file */
117
+ %local rc;
118
+ %let rc=%sysfunc(fdelete(&fref));
119
+ filename &fref clear;
120
+ %end;
121
+ %end;
122
+ %else %do;
123
+ %put %str(ERR)OR: &sysmacroname: &platform is unsupported!!!;
124
+ %let syscc=1012;
125
+ %end;
126
+
127
+ %mend mx_createfile;
@@ -45,14 +45,14 @@
45
45
  @li mv_jobflow.sas
46
46
 
47
47
  <h4> Related Programs </h4>
48
- @li mx_testservice.test.sas
48
+ @li mx_execute.test.sas
49
49
 
50
50
  @version 9.4
51
51
  @author Allan Bowe
52
52
 
53
53
  **/
54
54
 
55
- %macro mx_testservice(program,
55
+ %macro mx_execute(program,
56
56
  inputfiles=0,
57
57
  inputdatasets=0,
58
58
  inputparams=0,
@@ -296,4 +296,4 @@ filename &webref "&webrefpath";
296
296
  %put _local_;
297
297
  %end;
298
298
 
299
- %mend mx_testservice;
299
+ %mend mx_execute;
@@ -1,39 +0,0 @@
1
- /**
2
- @file
3
- @brief Executes a SASjs web service on SAS 9 or Viya
4
- @details Wraps the mx_testservice.sas macro (documentation can be found
5
- there)
6
-
7
- <h4> SAS Macros </h4>
8
- @li mx_testservice.sas
9
-
10
- @version 9.4
11
- @author Allan Bowe
12
-
13
- **/
14
-
15
- %macro mp_execute(program,
16
- inputfiles=0,
17
- inputdatasets=0,
18
- inputparams=0,
19
- debug=log,
20
- mdebug=0,
21
- outlib=0,
22
- outref=0,
23
- viyaresult=WEBOUT_JSON,
24
- viyacontext=SAS Job Execution compute context
25
- )/*/STORE SOURCE*/;
26
-
27
- %mx_testservice(&program,
28
- inputfiles=&inputfiles,
29
- inputdatasets=&inputdatasets,
30
- inputparams=&inputparams,
31
- debug=&debug,
32
- mdebug=&mdebug,
33
- outlib=&outlib,
34
- outref=&outref,
35
- viyaresult=&viyaresult,
36
- viyacontext=&viyacontext
37
- )
38
-
39
- %mend mp_execute;