@sasjs/core 4.26.1 → 4.27.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
@@ -31,14 +31,14 @@ Documentation: https://core.sasjs.io
31
31
 
32
32
  ## Components
33
33
 
34
- ### BASE library (All Platforms)
34
+ ### BASE folder (All Platforms)
35
35
 
36
36
  - OS independent
37
37
  - Works on all SAS Platforms
38
38
  - No X command
39
39
  - Prefixes: _mf_, _mp_
40
40
 
41
- ### DDL library (All Platforms)
41
+ ### DDL folder (All Platforms)
42
42
 
43
43
  - OS independent
44
44
  - Works on all SAS Platforms
@@ -47,14 +47,34 @@ Documentation: https://core.sasjs.io
47
47
 
48
48
  This library will not be used for storing data entries (such as formats or datalines). Where this becomes necessary in the future, a new repo will be created, in order to keep the NPM bundle size down (for the benefit of those looking to embed purely macros in their applications).
49
49
 
50
- ### FCMP library (All Platforms)
50
+ ### FCMP folder (All Platforms)
51
51
 
52
52
  - Function and macro names are identical, except for special cases
53
53
  - Prefixes: _mcf_
54
54
 
55
55
  The fcmp macros are used to generate fcmp functions, and can be used with or without the `proc fcmp` wrapper.
56
56
 
57
- ### META library (SAS9 only)
57
+ ### LUA folder
58
+
59
+ Wait - this is a macro library - what is LUA doing here? Well, it is a little known fact that you CAN run LUA within a SAS Macro. It has to be written to a text file with a `.lua` extension, from where you can `%include` it. So, without using the `proc lua` wrapper.
60
+
61
+ To contribute, simply write your freeform LUA in the LUA folder. Then run the `build.py`, which will convert all files with a ".lua" extension into a macro wrapper with an `ml_` prefix (embedding the necessary data step put statements). You can then use your module in any program by running:
62
+
63
+ ```sas
64
+ /* compile the lua module */
65
+ %ml_yourmodule()
66
+
67
+ /* Execute. Do not use the restart keyword! */
68
+ proc lua;
69
+ submit;
70
+ print(yourStuff);
71
+ endsubmit;
72
+ run;
73
+ ```
74
+
75
+ - Prefixes: _ml_
76
+
77
+ ### META folder (SAS9 only)
58
78
 
59
79
  Macros used in SAS EBI, which connect to the metadata server.
60
80
 
@@ -63,7 +83,14 @@ Macros used in SAS EBI, which connect to the metadata server.
63
83
  - No X command
64
84
  - Prefixes: _mm_
65
85
 
66
- ### SERVER library (@sasjs/server only)
86
+ ### METAX folder (SAS9 only)
87
+
88
+ - OS specific
89
+ - Metadata aware
90
+ - X command enabled
91
+ - Prefixes: _mmw_,_mmu_,_mmx_
92
+
93
+ ### SERVER folder (@sasjs/server only)
67
94
  These macros are used for building applications using [@sasjs/server](https://server.sasjs.io) - an open source REST API for Desktop SAS.
68
95
 
69
96
  - OS independent
@@ -71,7 +98,7 @@ These macros are used for building applications using [@sasjs/server](https://se
71
98
  - No X command
72
99
  - Prefixes: _ms_
73
100
 
74
- ### VIYA library (Viya only)
101
+ ### VIYA folder (Viya only)
75
102
 
76
103
  Macros used for interfacing with SAS Viya.
77
104
 
@@ -79,40 +106,29 @@ Macros used for interfacing with SAS Viya.
79
106
  - No X command
80
107
  - Prefixes: _mv_, _mvf_
81
108
 
82
- ### METAX library (SAS9 only)
109
+ ### XPLATFORM folder (Viya, Meta, and Server)
83
110
 
84
- - OS specific
85
- - Metadata aware
86
- - X command enabled
87
- - Prefixes: _mmw_,_mmu_,_mmx_
88
-
89
- ### LUA library
90
-
91
- Wait - this is a macro library - what is LUA doing here? Well, it is a little known fact that you CAN run LUA within a SAS Macro. It has to be written to a text file with a `.lua` extension, from where you can `%include` it. So, without using the `proc lua` wrapper.
92
-
93
- To contribute, simply write your freeform LUA in the LUA folder. Then run the `build.py`, which will convert all files with a ".lua" extension into a macro wrapper with an `ml_` prefix (embedding the necessary data step put statements). You can then use your module in any program by running:
94
-
95
- ```sas
96
- /* compile the lua module */
97
- %ml_yourmodule()
98
-
99
- /* Execute. Do not use the restart keyword! */
100
- proc lua;
101
- submit;
102
- print(yourStuff);
103
- endsubmit;
104
- run;
105
- ```
111
+ Sometimes it is helpful to use a macro that can be used interchangeably regardless of the server type on which is is running (SASVIYA, SAS9, SASJS).
106
112
 
107
- - Prefixes: _ml_
113
+ - OS independent
114
+ - No X command
115
+ - Prefixes: _mx_
108
116
 
109
117
  ## Installation
110
118
 
111
119
  First, download the repo to a location your SAS system can access. Then update your sasautos path to include the components you wish to have available, eg:
112
120
 
113
121
  ```sas
114
- options insert=(sasautos="/your/path/macrocore/base");
115
- options insert=(sasautos="/your/path/macrocore/meta");
122
+ %let repoloc=/your/path/core;
123
+ options insert=(sasautos="&repoloc/base");
124
+ options insert=(sasautos="&repoloc/ddl");
125
+ options insert=(sasautos="&repoloc/fcmp");
126
+ options insert=(sasautos="&repoloc/lua");
127
+ options insert=(sasautos="&repoloc/meta");
128
+ options insert=(sasautos="&repoloc/metax");
129
+ options insert=(sasautos="&repoloc/server");
130
+ options insert=(sasautos="&repoloc/viya");
131
+ options insert=(sasautos="&repoloc/xplatform");
116
132
  ```
117
133
 
118
134
  The above can be done directly in your sas program, via an autoexec, or an initialisation program.
@@ -142,7 +158,7 @@ filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
142
158
  - _mp_ for macro procedures (which generate sas code)
143
159
  - _ms_ for macro procedures that will only work with [@sasjs/server](https://github.com/sasjs/server)
144
160
  - _mv_ for macro procedures that will only work in Viya
145
- - _mx_ for macros that are XCMD enabled (working on both windows and unix)
161
+ - _mx_ for macros that work on Viya, SAS 9 EBI and SASjs Server
146
162
  - follow verb-noun convention
147
163
  - unix style line endings (lf)
148
164
  - individual lines should be no more than 80 characters long
@@ -5,8 +5,12 @@
5
5
 
6
6
  %put %mf_getplatform();
7
7
 
8
- returns:
9
- SASMETA (or SASVIYA)
8
+ returns one of:
9
+
10
+ @li SASMETA
11
+ @li SASVIYA
12
+ @li SASJS
13
+ @li BASESAS
10
14
 
11
15
  @param switch the param for which to return a platform specific variable
12
16
 
@@ -68,4 +72,4 @@
68
72
  %else %if &switch=VIYARESTAPI %then %do;
69
73
  %mf_trimstr(%sysfunc(getoption(servicesbaseurl)),/)
70
74
  %end;
71
- %mend mf_getplatform;
75
+ %mend mf_getplatform;
package/base/mf_isint.sas CHANGED
@@ -33,4 +33,4 @@
33
33
  %if %sysfunc(findc(%str(&val),,kd)) %then %do;0%end;
34
34
  %else %do;1%end;
35
35
 
36
- %mend mf_isint;
36
+ %mend mf_isint;
@@ -30,6 +30,7 @@
30
30
  @li mddl_dc_filtersummary.sas
31
31
  @li mddl_dc_locktable.sas
32
32
  @li mddl_dc_maxkeytable.sas
33
+ @li mf_getuniquename.sas
33
34
 
34
35
  <h4> Related Macros </h4>
35
36
  @li mp_filterstore.sas
@@ -46,7 +47,7 @@
46
47
  %macro mp_coretable(table_ref,libds=0
47
48
  )/*/STORE SOURCE*/;
48
49
  %local outds ;
49
- %let outds=%sysfunc(ifc(&libds=0,_data_,&libds));
50
+ %let outds=%sysfunc(ifc(&libds=0,%mf_getuniquename(),&libds));
50
51
  proc sql;
51
52
  %if &table_ref=DIFFTABLE %then %do;
52
53
  %mddl_dc_difftable(libds=&outds)
@@ -1,50 +1,13 @@
1
1
  /**
2
2
  @file mp_createwebservice.sas
3
- @brief Create a web service in SAS 9 or Viya
4
- @details Creates a SASJS ready Stored Process in SAS 9 or Job Execution
5
- Service in SAS Viya
3
+ @brief Create a web service in SAS 9, Viya or SASjs Server
4
+ @details This is actually a wrapper for mx_createwebservice.sas, remaining
5
+ for legacy purposes. For new apps, use mx_createwebservice.sas.
6
6
 
7
- Usage:
8
-
9
- %* compile macros ;
10
- filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
11
- %inc mc;
12
-
13
- %* write some code;
14
- filename ft15f001 temp;
15
- parmcards4;
16
- %* fetch any data from frontend ;
17
- %webout(FETCH)
18
- data example1 example2;
19
- set sashelp.class;
20
- run;
21
- %* send data back;
22
- %webout(OPEN)
23
- %webout(ARR,example1) * Array format, fast, suitable for large tables ;
24
- %webout(OBJ,example2) * Object format, easier to work with ;
25
- %webout(CLOSE)
26
- ;;;;
27
- %mp_createwebservice(path=/Public/app/common,name=appInit,replace=YES)
28
7
 
29
8
  <h4> SAS Macros </h4>
30
- @li mf_getplatform.sas
31
- @li mm_createwebservice.sas
32
- @li ms_createwebservice.sas
33
- @li mv_createwebservice.sas
9
+ @li mx_createwebservice.sas
34
10
 
35
- @param [in,out] path= The full folder path where the service will be created
36
- @param [in,out] name= Service name. Avoid spaces.
37
- @param [in] desc= The description of the service (optional)
38
- @param [in] precode= Space separated list of filerefs, pointing to the code
39
- that needs to be attached to the beginning of the service (optional)
40
- @param [in] code= (ft15f001) Space seperated fileref(s) of the actual code to
41
- be added
42
- @param [in] replace= (YES) Select YES to replace any existing service in that
43
- location
44
- @param [in] mDebug= (0) set to 1 to show debug messages in the log
45
-
46
- @version 9.2
47
- @author Allan Bowe
48
11
 
49
12
  **/
50
13
 
@@ -57,40 +20,13 @@ Usage:
57
20
  ,mdebug=0
58
21
  )/*/STORE SOURCE*/;
59
22
 
60
- %if &syscc ge 4 %then %do;
61
- %put syscc=&syscc - &sysmacroname will not execute in this state;
62
- %return;
63
- %end;
64
-
65
- %local platform; %let platform=%mf_getplatform();
66
- %if &platform=SASVIYA %then %do;
67
- %if "&path"="HOME" %then %let path=/Users/&sysuserid/My Folder;
68
- %mv_createwebservice(path=&path
69
- ,name=&name
70
- ,code=&code
71
- ,precode=&precode
72
- ,desc=&desc
73
- ,replace=&replace
74
- )
75
- %end;
76
- %else %if &platform=SASJS %then %do;
77
- %if "&path"="HOME" %then %let path=/Users/&_sasjs_username/My Folder;
78
- %ms_createwebservice(path=&path
23
+ %mx_createwebservice(path=&path
79
24
  ,name=&name
80
- ,code=&code
81
25
  ,precode=&precode
82
- ,mdebug=&mdebug
83
- )
84
- %end;
85
- %else %do;
86
- %if "&path"="HOME" %then %let path=/User Folders/&_METAPERSON/My Folder;
87
- %mm_createwebservice(path=&path
88
- ,name=&name
89
26
  ,code=&code
90
- ,precode=&precode
91
27
  ,desc=&desc
92
28
  ,replace=&replace
29
+ ,mdebug=&mdebug
93
30
  )
94
- %end;
95
31
 
96
32
  %mend mp_createwebservice;
@@ -1,53 +1,11 @@
1
1
  /**
2
2
  @file
3
- @brief Will execute a SASjs web service on SAS 9 or Viya
4
- @details Prepares the input files and retrieves the resulting datasets from
5
- the response JSON.
6
-
7
-
8
-
9
- Note - the _webout fileref should NOT be assigned prior to running this macro.
10
-
11
- @param [in] program The _PROGRAM endpoint to test
12
- @param [in] inputfiles=(0) A list of space seperated fileref:filename pairs as
13
- follows:
14
- inputfiles=inref:filename inref2:filename2
15
- @param [in] inputdatasets= (0) All datasets in this space seperated list are
16
- converted into SASJS-formatted CSVs (see mp_ds2csv.sas) files and added to
17
- the list of `inputfiles` for ingestion. The dataset will be sent with the
18
- same name (no need for a colon modifier).
19
- @param [in] inputparams=(0) A dataset containing name/value pairs in the
20
- following format:
21
- |name:$32|value:$1000|
22
- |---|---|
23
- |stpmacname|some value|
24
- |mustbevalidname|can be anything, oops, %abort!!|
25
-
26
- @param [in] debug= (log) Provide the _debug value
27
- @param [in] mdebug= (0) Set to 1 to provide macro debugging
28
- @param [in] viyaresult= (WEBOUT_JSON) The Viya result type to return. For
29
- more info, see mv_getjobresult.sas
30
- @param [in] viyacontext= (SAS Job Execution compute context) The Viya compute
31
- context on which to run the service
32
- @param [out] outlib= (0) Output libref to contain the final tables. Set to
33
- 0 if the service output is not in JSON format.
34
- @param [out] outref= (0) Output fileref to create, to contain the full _webout
35
- response.
3
+ @brief To be deprecated. Will execute a SASjs web service on SAS 9 or Viya
4
+ @details Use the mx_testservice.sas macro instead (documentation can be
5
+ found there)
36
6
 
37
7
  <h4> SAS Macros </h4>
38
- @li mf_getplatform.sas
39
- @li mf_getuniquefileref.sas
40
- @li mf_getuniquename.sas
41
- @li mp_abort.sas
42
- @li mp_binarycopy.sas
43
- @li mp_chop.sas
44
- @li mp_ds2csv.sas
45
- @li ms_testservice.sas
46
- @li mv_getjobresult.sas
47
- @li mv_jobflow.sas
48
-
49
- <h4> Related Programs </h4>
50
- @li mp_testservice.test.sas
8
+ @li mx_testservice.sas
51
9
 
52
10
  @version 9.4
53
11
  @author Allan Bowe
@@ -65,237 +23,17 @@
65
23
  viyaresult=WEBOUT_JSON,
66
24
  viyacontext=SAS Job Execution compute context
67
25
  )/*/STORE SOURCE*/;
68
- %local dbg pcnt fref1 fref2 webref webrefpath i webcount var platform;
69
- %if &mdebug=1 %then %do;
70
- %put &sysmacroname entry vars:;
71
- %put _local_;
72
- %end;
73
- %else %let dbg=*;
74
-
75
- /* sanitise inputparams */
76
- %let pcnt=0;
77
- %if &inputparams ne 0 %then %do;
78
- data _null_;
79
- set &inputparams;
80
- if not nvalid(name,'v7') then putlog (_all_)(=);
81
- else if name in (
82
- 'program','inputfiles','inputparams','debug','outlib','outref'
83
- ) then putlog (_all_)(=);
84
- else do;
85
- x+1;
86
- call symputx(name,quote(cats(value)),'l');
87
- call symputx(cats('pval',x),name,'l');
88
- call symputx('pcnt',x,'l');
89
- end;
90
- run;
91
- %mp_abort(iftrue= (%mf_nobs(&inputparams) ne &pcnt)
92
- ,mac=&sysmacroname
93
- ,msg=%str(Invalid values in &inputparams)
94
- )
95
- %end;
96
-
97
- /* convert inputdatasets to filerefs */
98
- %if "&inputdatasets" ne "0" %then %do;
99
- %if %quote(&inputfiles)=0 %then %let inputfiles=;
100
- %do i=1 %to %sysfunc(countw(&inputdatasets,%str( )));
101
- %let var=%scan(&inputdatasets,&i,%str( ));
102
- %local dsref&i;
103
- %let dsref&i=%mf_getuniquefileref();
104
- %mp_ds2csv(&var,outref=&&dsref&i,headerformat=SASJS)
105
- %let inputfiles=&inputfiles &&dsref&i:%scan(&var,-1,.);
106
- %end;
107
- %end;
108
-
109
- %let platform=%mf_getplatform();
110
- %let fref1=%mf_getuniquefileref();
111
- %let fref2=%mf_getuniquefileref();
112
- %let webref=%mf_getuniquefileref();
113
- %let webrefpath=%sysfunc(pathname(work))/%mf_getuniquename();
114
- /* mp_chop requires a physical path as input */
115
- filename &webref "&webrefpath";
116
-
117
- %if &platform=SASMETA %then %do;
118
-
119
- /* parse the input files */
120
- %if %quote(&inputfiles) ne 0 %then %do;
121
- %let webcount=%sysfunc(countw(&inputfiles));
122
- %put &=webcount;
123
- %do i=1 %to &webcount;
124
- %let var=%scan(&inputfiles,&i,%str( ));
125
- %local webfref&i webname&i;
126
- %let webref&i=%scan(&var,1,%str(:));
127
- %let webname&i=%scan(&var,2,%str(:));
128
- %put webref&i=&&webref&i;
129
- %put webname&i=&&webname&i;
130
- %end;
131
- %end;
132
- %else %let webcount=0;
133
-
134
- proc stp program="&program";
135
- inputparam _program="&program"
136
- %do i=1 %to &webcount;
137
- %if &webcount=1 %then %do;
138
- _webin_fileref="&&webref&i"
139
- _webin_name="&&webname&i"
140
- %end;
141
- %else %do;
142
- _webin_fileref&i="&&webref&i"
143
- _webin_name&i="&&webname&i"
144
- %end;
145
- %end;
146
- _webin_file_count="&webcount"
147
- _debug="&debug"
148
- %do i=1 %to &pcnt;
149
- /* resolve name only, proc stp fetches value */
150
- &&pval&i=&&&&&&pval&i
151
- %end;
152
- ;
153
- %do i=1 %to &webcount;
154
- inputfile &&webref&i;
155
- %end;
156
- outputfile _webout=&webref;
157
- run;
158
-
159
- data _null_;
160
- infile &webref;
161
- file &fref1;
162
- input;
163
- length line $10000;
164
- if index(_infile_,'>>weboutBEGIN<<') then do;
165
- line=tranwrd(_infile_,'>>weboutBEGIN<<','');
166
- put line;
167
- end;
168
- else if index(_infile_,'>>weboutEND<<') then do;
169
- line=tranwrd(_infile_,'>>weboutEND<<','');
170
- put line;
171
- stop;
172
- end;
173
- else put _infile_;
174
- run;
175
- data _null_;
176
- infile &fref1;
177
- input;
178
- put _infile_;
179
- run;
180
- %if &outlib ne 0 %then %do;
181
- libname &outlib json (&fref1);
182
- %end;
183
- %if &outref ne 0 %then %do;
184
- filename &outref temp;
185
- %mp_binarycopy(inref=&webref,outref=&outref)
186
- %end;
187
-
188
- %end;
189
- %else %if &platform=SASVIYA %then %do;
190
-
191
- /* prepare inputparams */
192
- %local ds1;
193
- %let ds1=%mf_getuniquename();
194
- %if "&inputparams" ne "0" %then %do;
195
- proc transpose data=&inputparams out=&ds1;
196
- id name;
197
- var value;
198
- run;
199
- %end;
200
- %else %do;
201
- data &ds1;run;
202
- %end;
203
-
204
- /* parse the input files - convert to sasjs params */
205
- %local webcount i var sasjs_tables;
206
- %if %quote(&inputfiles) ne 0 %then %do;
207
- %let webcount=%sysfunc(countw(&inputfiles));
208
- %put &=webcount;
209
- %do i=1 %to &webcount;
210
- %let var=%scan(&inputfiles,&i,%str( ));
211
- %local webfref&i webname&i sasjs&i.data;
212
- %let webref&i=%scan(&var,1,%str(:));
213
- %let webname&i=%scan(&var,2,%str(:));
214
- %put webref&i=&&webref&i;
215
- %put webname&i=&&webname&i;
216
-
217
- %let sasjs_tables=&sasjs_tables &&webname&i;
218
- data _null_;
219
- infile &&webref&i lrecl=32767;
220
- input;
221
- if _n_=1 then call symputx("sasjs&i.data",_infile_);
222
- else call symputx(
223
- "sasjs&i.data",cats(symget("sasjs&i.data"),'0D0A'x,_infile_)
224
- );
225
- putlog "&sysmacroname infile: " _infile_;
226
- run;
227
- data &ds1;
228
- set &ds1;
229
- length sasjs&i.data $32767 sasjs_tables $1000;
230
- sasjs&i.data=symget("sasjs&i.data");
231
- sasjs_tables=symget("sasjs_tables");
232
- run;
233
- %end;
234
- %end;
235
- %else %let webcount=0;
236
-
237
- data &ds1;
238
- retain _program "&program";
239
- retain _contextname "&viyacontext";
240
- set &ds1;
241
- putlog "&sysmacroname inputparams:";
242
- putlog (_all_)(=);
243
- run;
244
-
245
- %mv_jobflow(inds=&ds1
246
- ,maxconcurrency=1
247
- ,outds=work.results
248
- ,outref=&fref1
249
- ,mdebug=&mdebug
250
- )
251
- /* show the log */
252
- data _null_;
253
- infile &fref1;
254
- input;
255
- putlog _infile_;
256
- run;
257
- /* get the uri to fetch results */
258
- data _null_;
259
- set work.results;
260
- call symputx('uri',uri);
261
- putlog "&sysmacroname: fetching results for " uri;
262
- run;
263
- /* fetch results from webout.json */
264
- %mv_getjobresult(uri=&uri,
265
- result=&viyaresult,
266
- outref=&outref,
267
- outlib=&outlib,
268
- mdebug=&mdebug
269
- )
270
-
271
- %end;
272
- %else %if &platform=SASJS %then %do;
273
-
274
- %ms_testservice(&program
275
- ,inputfiles=&inputfiles
276
- ,inputdatasets=&inputdatasets
277
- ,inputparams=&inputparams
278
- ,debug=&debug
279
- ,mdebug=&mdebug
280
- ,outlib=&outlib
281
- ,outref=&outref
282
- )
283
-
284
- %end;
285
- %else %do;
286
- %put %str(ERR)OR: Unrecognised platform: &platform;
287
- %end;
288
-
289
- %if &mdebug=0 %then %do;
290
- filename &fref1 clear;
291
- %if &platform ne SASJS %then %do;
292
- filename &fref2 clear;
293
- filename &webref clear;
294
- %end;
295
- %end;
296
- %else %do;
297
- %put &sysmacroname exit vars:;
298
- %put _local_;
299
- %end;
300
26
 
301
- %mend mp_testservice;
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_testservice;
package/main.dox CHANGED
@@ -103,4 +103,15 @@
103
103
  * No X command
104
104
  * Prefixes: _mddl_
105
105
 
106
- */
106
+ */
107
+
108
+ /*! \dir xplatform
109
+ * \brief Cross Platform, works on all SAS servers (Viya, EBI, SASjs)
110
+ * \details Useful when you need to run a single piece of code against Viya,
111
+ SAS 9 with metadata, or SASjs on Base SAS.
112
+
113
+ * OS independent
114
+ * No X command
115
+ * Prefixes: _mx_
116
+
117
+ */
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "3.13.0"
37
37
  },
38
- "version": "4.26.1"
38
+ "version": "4.27.0"
39
39
  }
@@ -0,0 +1,96 @@
1
+ /**
2
+ @file mx_createwebservice.sas
3
+ @brief Create a web service in SAS 9, Viya or SASjs
4
+ @details Creates a SASJS ready Stored Process in SAS 9, a Job Execution
5
+ Service in SAS Viya, and a Stored Program on SASjs Server
6
+
7
+ Usage:
8
+
9
+ %* compile macros ;
10
+ filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
11
+ %inc mc;
12
+
13
+ %* write some code;
14
+ filename ft15f001 temp;
15
+ parmcards4;
16
+ %* fetch any data from frontend ;
17
+ %webout(FETCH)
18
+ data example1 example2;
19
+ set sashelp.class;
20
+ run;
21
+ %* send data back;
22
+ %webout(OPEN)
23
+ %webout(ARR,example1) * Array format, fast, suitable for large tables ;
24
+ %webout(OBJ,example2) * Object format, easier to work with ;
25
+ %webout(CLOSE)
26
+ ;;;;
27
+ %mp_createwebservice(path=/Public/app/common,name=appInit,replace=YES)
28
+
29
+ <h4> SAS Macros </h4>
30
+ @li mf_getplatform.sas
31
+ @li mm_createwebservice.sas
32
+ @li ms_createwebservice.sas
33
+ @li mv_createwebservice.sas
34
+
35
+ @param [in,out] path= The full folder path where the service will be created
36
+ @param [in,out] name= Service name. Avoid spaces.
37
+ @param [in] desc= The description of the service (optional)
38
+ @param [in] precode= Space separated list of filerefs, pointing to the code
39
+ that needs to be attached to the beginning of the service (optional)
40
+ @param [in] code= (ft15f001) Space seperated fileref(s) of the actual code to
41
+ be added
42
+ @param [in] replace= (YES) Select YES to replace any existing service in that
43
+ location
44
+ @param [in] mDebug= (0) set to 1 to show debug messages in the log
45
+
46
+ @version 9.2
47
+ @author Allan Bowe
48
+
49
+ **/
50
+
51
+ %macro mx_createwebservice(path=HOME
52
+ ,name=initService
53
+ ,precode=
54
+ ,code=ft15f001
55
+ ,desc=This service was created by the mp_createwebservice macro
56
+ ,replace=YES
57
+ ,mdebug=0
58
+ )/*/STORE SOURCE*/;
59
+
60
+ %if &syscc ge 4 %then %do;
61
+ %put syscc=&syscc - &sysmacroname will not execute in this state;
62
+ %return;
63
+ %end;
64
+
65
+ %local platform; %let platform=%mf_getplatform();
66
+ %if &platform=SASVIYA %then %do;
67
+ %if "&path"="HOME" %then %let path=/Users/&sysuserid/My Folder;
68
+ %mv_createwebservice(path=&path
69
+ ,name=&name
70
+ ,code=&code
71
+ ,precode=&precode
72
+ ,desc=&desc
73
+ ,replace=&replace
74
+ )
75
+ %end;
76
+ %else %if &platform=SASJS %then %do;
77
+ %if "&path"="HOME" %then %let path=/Users/&_sasjs_username/My Folder;
78
+ %ms_createwebservice(path=&path
79
+ ,name=&name
80
+ ,code=&code
81
+ ,precode=&precode
82
+ ,mdebug=&mdebug
83
+ )
84
+ %end;
85
+ %else %do;
86
+ %if "&path"="HOME" %then %let path=/User Folders/&_METAPERSON/My Folder;
87
+ %mm_createwebservice(path=&path
88
+ ,name=&name
89
+ ,code=&code
90
+ ,precode=&precode
91
+ ,desc=&desc
92
+ ,replace=&replace
93
+ )
94
+ %end;
95
+
96
+ %mend mx_createwebservice;
@@ -0,0 +1,57 @@
1
+ /**
2
+ @file
3
+ @brief Fetches code from Viya Job, SAS 9 STP, or SASjs Server STP
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 fetch the source
6
+ code from a Viya Job, SAS 9 Stored Process, or SASjs Stored Program.
7
+
8
+ The alternative would be to compile a generic macro in target-specific
9
+ folders (SASVIYA, SAS9 and SASJS). This avoids compiling unnecessary macros
10
+ at the expense of a more complex sasjsconfig.json setup.
11
+
12
+
13
+ @param [in] loc The full path to the Viya Job, SAS 9 Stored Process or SASjs
14
+ Stored Program in Drive or Metadata, WITHOUT the .sas extension (SASjs only)
15
+ @param [out] outref= (0) The fileref to create, which will contain the source
16
+ code.
17
+
18
+ <h4> SAS Macros </h4>
19
+ @li mf_getplatform.sas
20
+ @li mm_getstpcode.sas
21
+ @li ms_getfile.sas
22
+ @li mv_getjobcode.sas
23
+
24
+ @author Allan Bowe
25
+
26
+ **/
27
+
28
+ %macro mx_getcode(loc,outref=0
29
+ )/*/STORE SOURCE*/;
30
+
31
+ %local platform name shortloc;
32
+ %let platform=%mf_getplatform();
33
+
34
+ %if &platform=SASJS %then %do;
35
+ %ms_getfile(&loc..sas, outref=&outref)
36
+ %end;
37
+ %else %if &platform=SAS9 %then %do;
38
+ %mm_getstpcode(tree=&loc,outloc=&outref)
39
+ %end;
40
+ %else %if &platform=SASVIYA %then %do;
41
+ /* extract name & path from &loc */
42
+ data _null_;
43
+ loc=symget('loc');
44
+ name=scan(loc,-1,'/');
45
+ shortloc=substr(loc,1,length(loc)-length(name)-1);
46
+ call symputx('name',name,'l');
47
+ call symputx('shortloc',shortloc,'l');
48
+ run;
49
+ %mv_getjobcode(
50
+ path=&shortloc,
51
+ name=&name,
52
+ outref=&outref
53
+ )
54
+ %end;
55
+ %else %put &sysmacroname: &platform is unsupported!!!;
56
+
57
+ %mend mx_getcode;
@@ -0,0 +1,299 @@
1
+ /**
2
+ @file
3
+ @brief Will execute a SASjs web service on SAS 9, Viya or SASjs Server
4
+ @details Prepares the input files and retrieves the resulting datasets from
5
+ the response JSON.
6
+
7
+ Note - the _webout fileref should NOT be assigned prior to running this macro.
8
+
9
+ @param [in] program The _PROGRAM endpoint to test
10
+ @param [in] inputfiles=(0) A list of space seperated fileref:filename pairs as
11
+ follows:
12
+ inputfiles=inref:filename inref2:filename2
13
+ @param [in] inputdatasets= (0) All datasets in this space seperated list are
14
+ converted into SASJS-formatted CSVs (see mp_ds2csv.sas) files and added to
15
+ the list of `inputfiles` for ingestion. The dataset will be sent with the
16
+ same name (no need for a colon modifier).
17
+ @param [in] inputparams=(0) A dataset containing name/value pairs in the
18
+ following format:
19
+ |name:$32|value:$1000|
20
+ |---|---|
21
+ |stpmacname|some value|
22
+ |mustbevalidname|can be anything, oops, %abort!!|
23
+
24
+ @param [in] debug= (log) Provide the _debug value
25
+ @param [in] mdebug= (0) Set to 1 to provide macro debugging
26
+ @param [in] viyaresult= (WEBOUT_JSON) The Viya result type to return. For
27
+ more info, see mv_getjobresult.sas
28
+ @param [in] viyacontext= (SAS Job Execution compute context) The Viya compute
29
+ context on which to run the service
30
+ @param [out] outlib= (0) Output libref to contain the final tables. Set to
31
+ 0 if the service output is not in JSON format.
32
+ @param [out] outref= (0) Output fileref to create, to contain the full _webout
33
+ response.
34
+
35
+ <h4> SAS Macros </h4>
36
+ @li mf_getplatform.sas
37
+ @li mf_getuniquefileref.sas
38
+ @li mf_getuniquename.sas
39
+ @li mp_abort.sas
40
+ @li mp_binarycopy.sas
41
+ @li mp_chop.sas
42
+ @li mp_ds2csv.sas
43
+ @li ms_testservice.sas
44
+ @li mv_getjobresult.sas
45
+ @li mv_jobflow.sas
46
+
47
+ <h4> Related Programs </h4>
48
+ @li mx_testservice.test.sas
49
+
50
+ @version 9.4
51
+ @author Allan Bowe
52
+
53
+ **/
54
+
55
+ %macro mx_testservice(program,
56
+ inputfiles=0,
57
+ inputdatasets=0,
58
+ inputparams=0,
59
+ debug=log,
60
+ mdebug=0,
61
+ outlib=0,
62
+ outref=0,
63
+ viyaresult=WEBOUT_JSON,
64
+ viyacontext=SAS Job Execution compute context
65
+ );
66
+ %local dbg pcnt fref1 fref2 webref webrefpath i webcount var platform;
67
+ %if &mdebug=1 %then %do;
68
+ %put &sysmacroname entry vars:;
69
+ %put _local_;
70
+ %end;
71
+ %else %let dbg=*;
72
+
73
+ /* sanitise inputparams */
74
+ %let pcnt=0;
75
+ %if &inputparams ne 0 %then %do;
76
+ data _null_;
77
+ set &inputparams;
78
+ if not nvalid(name,'v7') then putlog (_all_)(=);
79
+ else if name in (
80
+ 'program','inputfiles','inputparams','debug','outlib','outref'
81
+ ) then putlog (_all_)(=);
82
+ else do;
83
+ x+1;
84
+ call symputx(name,quote(cats(value)),'l');
85
+ call symputx(cats('pval',x),name,'l');
86
+ call symputx('pcnt',x,'l');
87
+ end;
88
+ run;
89
+ %mp_abort(iftrue= (%mf_nobs(&inputparams) ne &pcnt)
90
+ ,mac=&sysmacroname
91
+ ,msg=%str(Invalid values in &inputparams)
92
+ )
93
+ %end;
94
+
95
+ /* convert inputdatasets to filerefs */
96
+ %if "&inputdatasets" ne "0" %then %do;
97
+ %if %quote(&inputfiles)=0 %then %let inputfiles=;
98
+ %do i=1 %to %sysfunc(countw(&inputdatasets,%str( )));
99
+ %let var=%scan(&inputdatasets,&i,%str( ));
100
+ %local dsref&i;
101
+ %let dsref&i=%mf_getuniquefileref();
102
+ %mp_ds2csv(&var,outref=&&dsref&i,headerformat=SASJS)
103
+ %let inputfiles=&inputfiles &&dsref&i:%scan(&var,-1,.);
104
+ %end;
105
+ %end;
106
+
107
+ %let platform=%mf_getplatform();
108
+ %let fref1=%mf_getuniquefileref();
109
+ %let fref2=%mf_getuniquefileref();
110
+ %let webref=%mf_getuniquefileref();
111
+ %let webrefpath=%sysfunc(pathname(work))/%mf_getuniquename();
112
+ /* mp_chop requires a physical path as input */
113
+ filename &webref "&webrefpath";
114
+
115
+ %if &platform=SASMETA %then %do;
116
+
117
+ /* parse the input files */
118
+ %if %quote(&inputfiles) ne 0 %then %do;
119
+ %let webcount=%sysfunc(countw(&inputfiles));
120
+ %put &=webcount;
121
+ %do i=1 %to &webcount;
122
+ %let var=%scan(&inputfiles,&i,%str( ));
123
+ %local webfref&i webname&i;
124
+ %let webref&i=%scan(&var,1,%str(:));
125
+ %let webname&i=%scan(&var,2,%str(:));
126
+ %put webref&i=&&webref&i;
127
+ %put webname&i=&&webname&i;
128
+ %end;
129
+ %end;
130
+ %else %let webcount=0;
131
+
132
+ proc stp program="&program";
133
+ inputparam _program="&program"
134
+ %do i=1 %to &webcount;
135
+ %if &webcount=1 %then %do;
136
+ _webin_fileref="&&webref&i"
137
+ _webin_name="&&webname&i"
138
+ %end;
139
+ %else %do;
140
+ _webin_fileref&i="&&webref&i"
141
+ _webin_name&i="&&webname&i"
142
+ %end;
143
+ %end;
144
+ _webin_file_count="&webcount"
145
+ _debug="&debug"
146
+ %do i=1 %to &pcnt;
147
+ /* resolve name only, proc stp fetches value */
148
+ &&pval&i=&&&&&&pval&i
149
+ %end;
150
+ ;
151
+ %do i=1 %to &webcount;
152
+ inputfile &&webref&i;
153
+ %end;
154
+ outputfile _webout=&webref;
155
+ run;
156
+
157
+ data _null_;
158
+ infile &webref;
159
+ file &fref1;
160
+ input;
161
+ length line $10000;
162
+ if index(_infile_,'>>weboutBEGIN<<') then do;
163
+ line=tranwrd(_infile_,'>>weboutBEGIN<<','');
164
+ put line;
165
+ end;
166
+ else if index(_infile_,'>>weboutEND<<') then do;
167
+ line=tranwrd(_infile_,'>>weboutEND<<','');
168
+ put line;
169
+ stop;
170
+ end;
171
+ else put _infile_;
172
+ run;
173
+ data _null_;
174
+ infile &fref1;
175
+ input;
176
+ put _infile_;
177
+ run;
178
+ %if &outlib ne 0 %then %do;
179
+ libname &outlib json (&fref1);
180
+ %end;
181
+ %if &outref ne 0 %then %do;
182
+ filename &outref temp;
183
+ %mp_binarycopy(inref=&webref,outref=&outref)
184
+ %end;
185
+
186
+ %end;
187
+ %else %if &platform=SASVIYA %then %do;
188
+
189
+ /* prepare inputparams */
190
+ %local ds1;
191
+ %let ds1=%mf_getuniquename();
192
+ %if "&inputparams" ne "0" %then %do;
193
+ proc transpose data=&inputparams out=&ds1;
194
+ id name;
195
+ var value;
196
+ run;
197
+ %end;
198
+ %else %do;
199
+ data &ds1;run;
200
+ %end;
201
+
202
+ /* parse the input files - convert to sasjs params */
203
+ %local webcount i var sasjs_tables;
204
+ %if %quote(&inputfiles) ne 0 %then %do;
205
+ %let webcount=%sysfunc(countw(&inputfiles));
206
+ %put &=webcount;
207
+ %do i=1 %to &webcount;
208
+ %let var=%scan(&inputfiles,&i,%str( ));
209
+ %local webfref&i webname&i sasjs&i.data;
210
+ %let webref&i=%scan(&var,1,%str(:));
211
+ %let webname&i=%scan(&var,2,%str(:));
212
+ %put webref&i=&&webref&i;
213
+ %put webname&i=&&webname&i;
214
+
215
+ %let sasjs_tables=&sasjs_tables &&webname&i;
216
+ data _null_;
217
+ infile &&webref&i lrecl=32767;
218
+ input;
219
+ if _n_=1 then call symputx("sasjs&i.data",_infile_);
220
+ else call symputx(
221
+ "sasjs&i.data",cats(symget("sasjs&i.data"),'0D0A'x,_infile_)
222
+ );
223
+ putlog "&sysmacroname infile: " _infile_;
224
+ run;
225
+ data &ds1;
226
+ set &ds1;
227
+ length sasjs&i.data $32767 sasjs_tables $1000;
228
+ sasjs&i.data=symget("sasjs&i.data");
229
+ sasjs_tables=symget("sasjs_tables");
230
+ run;
231
+ %end;
232
+ %end;
233
+ %else %let webcount=0;
234
+
235
+ data &ds1;
236
+ retain _program "&program";
237
+ retain _contextname "&viyacontext";
238
+ set &ds1;
239
+ putlog "&sysmacroname inputparams:";
240
+ putlog (_all_)(=);
241
+ run;
242
+
243
+ %mv_jobflow(inds=&ds1
244
+ ,maxconcurrency=1
245
+ ,outds=work.results
246
+ ,outref=&fref1
247
+ ,mdebug=&mdebug
248
+ )
249
+ /* show the log */
250
+ data _null_;
251
+ infile &fref1;
252
+ input;
253
+ putlog _infile_;
254
+ run;
255
+ /* get the uri to fetch results */
256
+ data _null_;
257
+ set work.results;
258
+ call symputx('uri',uri);
259
+ putlog "&sysmacroname: fetching results for " uri;
260
+ run;
261
+ /* fetch results from webout.json */
262
+ %mv_getjobresult(uri=&uri,
263
+ result=&viyaresult,
264
+ outref=&outref,
265
+ outlib=&outlib,
266
+ mdebug=&mdebug
267
+ )
268
+
269
+ %end;
270
+ %else %if &platform=SASJS %then %do;
271
+
272
+ %ms_testservice(&program
273
+ ,inputfiles=&inputfiles
274
+ ,inputdatasets=&inputdatasets
275
+ ,inputparams=&inputparams
276
+ ,debug=&debug
277
+ ,mdebug=&mdebug
278
+ ,outlib=&outlib
279
+ ,outref=&outref
280
+ )
281
+
282
+ %end;
283
+ %else %do;
284
+ %put %str(ERR)OR: Unrecognised platform: &platform;
285
+ %end;
286
+
287
+ %if &mdebug=0 %then %do;
288
+ filename &fref1 clear;
289
+ %if &platform ne SASJS %then %do;
290
+ filename &fref2 clear;
291
+ filename &webref clear;
292
+ %end;
293
+ %end;
294
+ %else %do;
295
+ %put &sysmacroname exit vars:;
296
+ %put _local_;
297
+ %end;
298
+
299
+ %mend mx_testservice;