@sasjs/core 4.0.0 → 4.3.1

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.
@@ -1,12 +1,10 @@
1
1
  /**
2
- @file mp_testservice.sas
3
- @brief Will execute a test against a SASjs web service on SAS 9 or Viya
2
+ @file
3
+ @brief Will execute a SASjs web service on SAS 9 or Viya
4
4
  @details Prepares the input files and retrieves the resulting datasets from
5
5
  the response JSON.
6
6
 
7
- %mp_testjob(
8
- duration=60*5
9
- )
7
+
10
8
 
11
9
  Note - the _webout fileref should NOT be assigned prior to running this macro.
12
10
 
@@ -14,6 +12,10 @@
14
12
  @param [in] inputfiles=(0) A list of space seperated fileref:filename pairs as
15
13
  follows:
16
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).
17
19
  @param [in] inputparams=(0) A dataset containing name/value pairs in the
18
20
  following format:
19
21
  |name:$32|value:$1000|
@@ -38,9 +40,13 @@
38
40
  @li mf_getuniquename.sas
39
41
  @li mp_abort.sas
40
42
  @li mp_binarycopy.sas
43
+ @li mp_ds2csv.sas
41
44
  @li mv_getjobresult.sas
42
45
  @li mv_jobflow.sas
43
46
 
47
+ <h4> Related Programs </h4>
48
+ @li mp_testservice.test.sas
49
+
44
50
  @version 9.4
45
51
  @author Allan Bowe
46
52
 
@@ -48,6 +54,7 @@
48
54
 
49
55
  %macro mp_testservice(program,
50
56
  inputfiles=0,
57
+ inputdatasets=0,
51
58
  inputparams=0,
52
59
  debug=log,
53
60
  mdebug=0,
@@ -56,7 +63,7 @@
56
63
  viyaresult=WEBOUT_JSON,
57
64
  viyacontext=SAS Job Execution compute context
58
65
  )/*/STORE SOURCE*/;
59
- %local dbg;
66
+ %local dbg pcnt fref1 webref i webcount var platform;
60
67
  %if &mdebug=1 %then %do;
61
68
  %put &sysmacroname entry vars:;
62
69
  %put _local_;
@@ -64,7 +71,6 @@
64
71
  %else %let dbg=*;
65
72
 
66
73
  /* sanitise inputparams */
67
- %local pcnt;
68
74
  %let pcnt=0;
69
75
  %if &inputparams ne 0 %then %do;
70
76
  data _null_;
@@ -86,17 +92,25 @@
86
92
  )
87
93
  %end;
88
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
+
89
107
 
90
- %local fref1 webref;
91
108
  %let fref1=%mf_getuniquefileref();
92
109
  %let webref=%mf_getuniquefileref();
93
-
94
- %local platform;
95
110
  %let platform=%mf_getplatform();
96
111
  %if &platform=SASMETA %then %do;
97
112
 
98
113
  /* parse the input files */
99
- %local webcount i var;
100
114
  %if %quote(&inputfiles) ne 0 %then %do;
101
115
  %let webcount=%sysfunc(countw(&inputfiles));
102
116
  %put &=webcount;
@@ -0,0 +1,110 @@
1
+ /**
2
+ @file
3
+ @brief Returns the type of the format
4
+ @details
5
+ Returns the type, eg DATE / DATETIME / TIME (based on hard-coded lookup)
6
+ else CHAR / NUM.
7
+
8
+ This macro may be extended in the future to support custom formats - this
9
+ would necessitate a call to `dosubl()` for running a proc format with cntlout.
10
+
11
+ The function itself takes the following (positional) parameters:
12
+
13
+ | PARAMETER | DESCRIPTION |
14
+ |---|---|
15
+ |fmtnm| Format name to be tested. Can be with or without the w.d extension.|
16
+
17
+ Usage:
18
+
19
+ %mcf_getfmttype(wrap=YES, insert_cmplib=YES)
20
+
21
+ data _null_;
22
+ fmt1=mcf_getfmttype('DATE9.');
23
+ fmt2=mcf_getfmttype('DATETIME');
24
+ put (fmt:)(=);
25
+ run;
26
+ %put fmt3=%sysfunc(mcf_getfmttype(TIME9.));
27
+
28
+ Returns:
29
+
30
+ > fmt1=DATE fmt2=DATETIME
31
+ > fmt3=TIME
32
+
33
+ @param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
34
+ @param [out] insert_cmplib= (NO) Choose YES to insert the package into the
35
+ CMPLIB reference.
36
+ @param [out] lib= (work) The output library in which to create the catalog.
37
+ @param [out] cat= (sasjs) The output catalog in which to create the package.
38
+ @param [out] pkg= (utils) The output package in which to create the function.
39
+ Uses a 3 part format: libref.catalog.package
40
+
41
+ <h4> SAS Macros </h4>
42
+ @li mcf_init.sas
43
+
44
+ <h4> Related Programs </h4>
45
+ @li mcf_getfmttype.test.sas
46
+ @li mp_init.sas
47
+
48
+ @todo "Custom Format Lookups" To enable site-specific formats, make
49
+ use of a set of SASJS_FMTLIST_(DATATYPE) global variables.
50
+
51
+ **/
52
+
53
+ %macro mcf_getfmttype(wrap=NO
54
+ ,insert_cmplib=NO
55
+ ,lib=WORK
56
+ ,cat=SASJS
57
+ ,pkg=UTILS
58
+ )/*/STORE SOURCE*/;
59
+
60
+ %if %mcf_init(mcf_getfmttype)=1 %then %return;
61
+
62
+ %if &wrap=YES %then %do;
63
+ proc fcmp outlib=&lib..&cat..&pkg;
64
+ %end;
65
+
66
+ function mcf_getfmttype(fmtnm $) $8;
67
+ if substr(fmtnm,1,1)='$' then return('CHAR');
68
+ else do;
69
+ /* extract NAME */
70
+ length fmt $32;
71
+ fmt=scan(fmtnm,1,'.');
72
+ do while (
73
+ substr(fmt,length(fmt),1) in ('1','2','3','4','5','6','7','8','9','0')
74
+ );
75
+ if length(fmt)=1 then fmt='W';
76
+ else fmt=substr(fmt,1,length(fmt)-1);
77
+ end;
78
+
79
+ /* apply lookups */
80
+ if cats(fmt) in ('DATETIME','B8601DN','B8601DN','B8601DT','B8601DT'
81
+ ,'B8601DZ','B8601DZ','DATEAMPM','DTDATE','DTMONYY','DTWKDATX','DTYEAR'
82
+ ,'DTYYQC','E8601DN','E8601DN','E8601DT','E8601DT','E8601DZ','E8601DZ')
83
+ then return('DATETIME');
84
+ else if fmt in ('DATE','YYMMDD','B8601DA','B8601DA','DAY','DDMMYY'
85
+ ,'DDMMYYB','DDMMYYC','DDMMYYD','DDMMYYN','DDMMYYP','DDMMYYS','DDMMYYx'
86
+ ,'DOWNAME','E8601DA','E8601DA','JULDAY','JULIAN','MMDDYY','MMDDYYB'
87
+ ,'MMDDYYC','MMDDYYD','MMDDYYN','MMDDYYP','MMDDYYS','MMDDYYx','MMYY'
88
+ ,'MMYYC','MMYYD','MMYYN','MMYYP','MMYYS','MMYYx','MONNAME','MONTH'
89
+ ,'MONYY','PDJULG','PDJULI','QTR','QTRR','WEEKDATE','WEEKDATX','WEEKDAY'
90
+ ,'WEEKU','WEEKV','WEEKW','WORDDATE','WORDDATX','YEAR','YYMM','YYMMC'
91
+ ,'YYMMD','YYMMDDB','YYMMDDC','YYMMDDD','YYMMDDN','YYMMDDP','YYMMDDS'
92
+ ,'YYMMDDx','YYMMN','YYMMP','YYMMS','YYMMx','YYMON','YYQ','YYQC','YYQD'
93
+ ,'YYQN','YYQP','YYQR','YYQRC','YYQRD','YYQRN','YYQRP','YYQRS','YYQRx'
94
+ ,'YYQS','YYQx','YYQZ') then return('DATE');
95
+ else if fmt in ('TIME','B8601LZ','B8601LZ','B8601TM','B8601TM','B8601TZ'
96
+ ,'B8601TZ','E8601LZ','E8601LZ','E8601TM','E8601TM','E8601TZ','E8601TZ'
97
+ ,'HHMM','HOUR','MMSS','TIMEAMPM','TOD') then return('TIME');
98
+ else return('NUM');
99
+ end;
100
+ endsub;
101
+
102
+ %if &wrap=YES %then %do;
103
+ quit;
104
+ %end;
105
+
106
+ %if &insert_cmplib=YES %then %do;
107
+ options insert=(CMPLIB=(&lib..&cat));
108
+ %end;
109
+
110
+ %mend mcf_getfmttype;
@@ -0,0 +1,44 @@
1
+ /**
2
+ @file
3
+ @brief Sets up the mcf_xx functions
4
+ @details
5
+ There is no (efficient) way to determine if an mcf_xx macro has already been
6
+ invoked. So, we make use of a global macro variable list to keep track.
7
+
8
+ Usage:
9
+
10
+ %mcf_init(MCF_LENGTH)
11
+
12
+ Returns:
13
+
14
+ > 1 (if already initialised) else 0
15
+
16
+ @param [in] func The function to be initialised
17
+
18
+ <h4> Related Macros </h4>
19
+ @li mcf_init.test.sas
20
+
21
+ **/
22
+
23
+ %macro mcf_init(func
24
+ )/*/STORE SOURCE*/;
25
+
26
+ %if not (%symexist(SASJS_PREFIX)) %then %do;
27
+ %global SASJS_PREFIX;
28
+ %let SASJS_PREFIX=SASJS;
29
+ %end;
30
+
31
+ %let func=%upcase(&func);
32
+
33
+ /* the / character is just a seperator */
34
+ %global &sasjs_prefix._FUNCTIONS;
35
+ %if %index(&&&sasjs_prefix._FUNCTIONS,&func/)>0 %then %do;
36
+ 1
37
+ %return;
38
+ %end;
39
+ %else %do;
40
+ %let &sasjs_prefix._FUNCTIONS=&&&sasjs_prefix._FUNCTIONS &func/;
41
+ 0
42
+ %end;
43
+
44
+ %mend mcf_init;
@@ -40,10 +40,11 @@
40
40
  Uses a 3 part format: libref.catalog.package
41
41
 
42
42
  <h4> SAS Macros </h4>
43
- @li mf_existfunction.sas
43
+ @li mcf_init.sas
44
44
 
45
- <h4> Related Macros </h4>
45
+ <h4> Related Programs </h4>
46
46
  @li mcf_length.test.sas
47
+ @li mp_init.sas
47
48
 
48
49
  **/
49
50
 
@@ -54,7 +55,7 @@
54
55
  ,pkg=UTILS
55
56
  )/*/STORE SOURCE*/;
56
57
 
57
- %if %mf_existfunction(mcf_length)=1 %then %return;
58
+ %if %mcf_init(mcf_length)=1 %then %return;
58
59
 
59
60
  %if &wrap=YES %then %do;
60
61
  proc fcmp outlib=&lib..&cat..&pkg;
@@ -55,7 +55,11 @@
55
55
  Uses a 3 part format: libref.catalog.package
56
56
 
57
57
  <h4> SAS Macros </h4>
58
- @li mf_existfunction.sas
58
+ @li mcf_init.sas
59
+
60
+ <h4> Related Programs </h4>
61
+ @li mcf_stpsrv_header.test.sas
62
+ @li mp_init.sas
59
63
 
60
64
  **/
61
65
 
@@ -66,7 +70,7 @@
66
70
  ,pkg=UTILS
67
71
  )/*/STORE SOURCE*/;
68
72
 
69
- %if %mf_existfunction(stpsrv_header)=1 %then %return;
73
+ %if %mcf_init(stpsrv_header)=1 %then %return;
70
74
 
71
75
  %if &wrap=YES %then %do;
72
76
  proc fcmp outlib=&lib..&cat..&pkg;
@@ -40,7 +40,11 @@
40
40
  Uses a 3 part format: libref.catalog.package
41
41
 
42
42
  <h4> SAS Macros </h4>
43
- @li mf_existfunction.sas
43
+ @li mcf_init.sas
44
+
45
+ <h4> Related Programs </h4>
46
+ @li mcf_stpsrv_header.test.sas
47
+ @li mp_init.sas
44
48
 
45
49
  **/
46
50
 
@@ -51,7 +55,7 @@
51
55
  ,pkg=UTILS
52
56
  )/*/STORE SOURCE*/;
53
57
 
54
- %if %mf_existfunction(mcf_string2file)=1 %then %return;
58
+ %if %mcf_init(mcf_string2file)=1 %then %return;
55
59
 
56
60
  %if &wrap=YES %then %do;
57
61
  proc fcmp outlib=&lib..&cat..&pkg;
@@ -177,6 +177,7 @@ run;
177
177
 
178
178
  data &outds (keep=stpuri prompturi fileuri texturi);
179
179
  length stpuri prompturi fileuri texturi serveruri $256 ;
180
+ if _n_=1 then call missing (of _all_);
180
181
  set &outds;
181
182
 
182
183
  /* final checks on uris */
@@ -164,7 +164,7 @@ data _null_;
164
164
  put ' %put &sysmacroname: Switching to DATASTEP engine; ';
165
165
  put ' %goto datastep; ';
166
166
  put ' %end; ';
167
- put ' data &tempds /view=&tempds;set &ds; ';
167
+ put ' data &tempds;set &ds; ';
168
168
  put ' %if &fmt=N %then format _numeric_ best32.;; ';
169
169
  put ' /* PRETTY is necessary to avoid line truncation in large files */ ';
170
170
  put ' proc json out=&jref pretty ';
@@ -190,7 +190,12 @@ data _null_;
190
190
  put ' )); ';
191
191
  put ' %do i=1 %to &numcols; ';
192
192
  put ' length &&name&i $&&len&i; ';
193
- put ' &&name&i=left(put(&&newname&i,&&fmt&i)); ';
193
+ put ' %if &&typelong&i=num %then %do; ';
194
+ put ' &&name&i=left(put(&&newname&i,&&fmt&i)); ';
195
+ put ' %end; ';
196
+ put ' %else %do; ';
197
+ put ' &&name&i=put(&&newname&i,&&fmt&i); ';
198
+ put ' %end; ';
194
199
  put ' drop &&newname&i; ';
195
200
  put ' %end; ';
196
201
  put ' if _error_ then call symputx(''syscc'',1012); ';
@@ -210,7 +215,7 @@ data _null_;
210
215
  put ' %end; ';
211
216
  put ' other = [best.]; ';
212
217
  put ' ';
213
- put ' data &tempds/view=&tempds; ';
218
+ put ' data &tempds; ';
214
219
  put ' attrib _all_ label=''''; ';
215
220
  put ' %do i=1 %to &numcols; ';
216
221
  put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
@@ -272,8 +277,7 @@ data _null_;
272
277
  put ' %end; ';
273
278
  put ' ';
274
279
  put ' proc sql; ';
275
- put ' drop view &tempds; ';
276
- put ' drop table &colinfo; ';
280
+ put ' drop table &colinfo, &tempds; ';
277
281
  put ' ';
278
282
  put ' %if &showmeta=YES %then %do; ';
279
283
  put ' data _null_; file &jref encoding=''utf-8'' mod; ';
@@ -1,21 +1,28 @@
1
1
  /**
2
2
  @file
3
3
  @brief Creates dataset with all members of a metadata group
4
- @details
4
+ @details This macro will query SAS metadata and return all the members
5
+ of a particular group.
5
6
 
6
- usage:
7
+ Usage:
7
8
 
8
- %mm_getgroupmembers(someGroupName
9
- ,outds=work.mm_getgroupmembers
10
- ,emails=YES)
9
+ %mm_getgroupmembers(someGroupName
10
+ ,outds=work.mm_getgroupmembers
11
+ ,emails=YES
12
+ )
11
13
 
12
14
  @param group metadata group for which to bring back members
13
- @param outds= the dataset to create that contains the list of members
14
- @param emails= set to YES to bring back email addresses
15
- @param id= set to yes if passing an ID rather than a group name
15
+ @param outds= (work.mm_getgroupmembers) The dataset to create that contains
16
+ the list of members
17
+ @param emails= (NO) Set to YES to bring back email addresses
18
+ @param id= (NO) Set to yes if passing an ID rather than a group name
16
19
 
17
20
  @returns outds dataset containing all members of the metadata group
18
21
 
22
+ <h4> Related Macros </h4>
23
+ @li mm_getgorups.sas
24
+ @li mm_adduser2group.sas
25
+
19
26
  @version 9.2
20
27
  @author Allan Bowe
21
28
 
@@ -41,7 +41,11 @@ run;
41
41
 
42
42
  filename __mc1 temp;
43
43
  filename __mc2 temp;
44
- data &outds; length serveruri servername $200; stop;run;
44
+ data &outds;
45
+ length serveruri servername $200;
46
+ call missing (of _all_);
47
+ stop;
48
+ run;
45
49
  %do x=1 %to &repocnt;
46
50
  options metarepository=&&repo&x;
47
51
  proc metadata in=
@@ -60,13 +64,16 @@ data &outds; length serveruri servername $200; stop;run;
60
64
  data _null_;
61
65
  file __mc2;
62
66
  put '<SXLEMAP version="1.2" name="SASContexts"><TABLE name="SASContexts">';
63
- put "<TABLE-PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext</TABLE-PATH>";
67
+ put "<TABLE-PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext";
68
+ put "</TABLE-PATH>";
64
69
  put '<COLUMN name="serveruri">';
65
- put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext/@Id</PATH>";
70
+ put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext/@Id";
71
+ put "</PATH>";
66
72
  put "<TYPE>character</TYPE><DATATYPE>string</DATATYPE><LENGTH>200</LENGTH>";
67
73
  put '</COLUMN>';
68
74
  put '<COLUMN name="servername">';
69
- put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext/@Name</PATH>";
75
+ put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext/@Name";
76
+ put "</PATH>";
70
77
  put "<TYPE>character</TYPE><DATATYPE>string</DATATYPE><LENGTH>200</LENGTH>";
71
78
  put '</COLUMN>';
72
79
  put '</TABLE></SXLEMAP>';
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "3.6.0"
37
37
  },
38
- "version": "4.0.0"
38
+ "version": "4.3.1"
39
39
  }
@@ -308,7 +308,7 @@ data _null_;
308
308
  put ' %put &sysmacroname: Switching to DATASTEP engine; ';
309
309
  put ' %goto datastep; ';
310
310
  put ' %end; ';
311
- put ' data &tempds /view=&tempds;set &ds; ';
311
+ put ' data &tempds;set &ds; ';
312
312
  put ' %if &fmt=N %then format _numeric_ best32.;; ';
313
313
  put ' /* PRETTY is necessary to avoid line truncation in large files */ ';
314
314
  put ' proc json out=&jref pretty ';
@@ -334,7 +334,12 @@ data _null_;
334
334
  put ' )); ';
335
335
  put ' %do i=1 %to &numcols; ';
336
336
  put ' length &&name&i $&&len&i; ';
337
- put ' &&name&i=left(put(&&newname&i,&&fmt&i)); ';
337
+ put ' %if &&typelong&i=num %then %do; ';
338
+ put ' &&name&i=left(put(&&newname&i,&&fmt&i)); ';
339
+ put ' %end; ';
340
+ put ' %else %do; ';
341
+ put ' &&name&i=put(&&newname&i,&&fmt&i); ';
342
+ put ' %end; ';
338
343
  put ' drop &&newname&i; ';
339
344
  put ' %end; ';
340
345
  put ' if _error_ then call symputx(''syscc'',1012); ';
@@ -354,7 +359,7 @@ data _null_;
354
359
  put ' %end; ';
355
360
  put ' other = [best.]; ';
356
361
  put ' ';
357
- put ' data &tempds/view=&tempds; ';
362
+ put ' data &tempds; ';
358
363
  put ' attrib _all_ label=''''; ';
359
364
  put ' %do i=1 %to &numcols; ';
360
365
  put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
@@ -416,8 +421,7 @@ data _null_;
416
421
  put ' %end; ';
417
422
  put ' ';
418
423
  put ' proc sql; ';
419
- put ' drop view &tempds; ';
420
- put ' drop table &colinfo; ';
424
+ put ' drop table &colinfo, &tempds; ';
421
425
  put ' ';
422
426
  put ' %if &showmeta=YES %then %do; ';
423
427
  put ' data _null_; file &jref encoding=''utf-8'' mod; ';