@sasjs/core 2.56.0 → 2.57.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.
@@ -5,7 +5,7 @@
5
5
  Run without arguments to see a list of detectable features.
6
6
  Note - this list is based on known versions of SAS rather than
7
7
  actual feature detection, as that is tricky / impossible to do
8
- without generating errors in most cases.
8
+ without generating errs in most cases.
9
9
 
10
10
  %put %mf_existfeature(PROCLUA);
11
11
 
@@ -10,7 +10,7 @@
10
10
  @param attr full list in [documentation](
11
11
  https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000147794.htm)
12
12
  @return output returns result of the attrc value supplied, or -1 and log
13
- message if error.
13
+ message if err.
14
14
 
15
15
  @version 9.2
16
16
  @author Allan Bowe
@@ -10,7 +10,7 @@
10
10
  @param attr Common values are NLOBS and NVARS, full list in [documentation](
11
11
  http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212040.htm)
12
12
  @return output returns result of the attrn value supplied, or -1 and log
13
- message if error.
13
+ message if err.
14
14
 
15
15
  @version 9.2
16
16
  @author Allan Bowe
package/base/mf_mkdir.sas CHANGED
@@ -51,7 +51,7 @@ Usage:
51
51
  %end;
52
52
 
53
53
  /*
54
- Now create the directory. Complain loudly of any errors.
54
+ Now create the directory. Complain loudly of any errs.
55
55
  */
56
56
 
57
57
  %let dname = %sysfunc(dcreate(&child, &parent));
package/base/mf_nobs.sas CHANGED
@@ -12,7 +12,7 @@
12
12
  @param libds library.dataset
13
13
 
14
14
  @return output returns result of the attrn value supplied, or log message
15
- if error.
15
+ if err.
16
16
 
17
17
 
18
18
  @version 9.2
@@ -55,6 +55,8 @@
55
55
  /* create folders and copy content */
56
56
  data _null_;
57
57
  set work.&tempds;
58
+ length msg $256;
59
+ call missing(msg);
58
60
  if _n_ = 1 then dpos+sum(length(directory),2);
59
61
  filepath2="&target/"!!substr(filepath,dpos);
60
62
  if file_or_folder='folder' then call execute('%mf_mkdir('!!filepath2!!')');
@@ -63,9 +65,9 @@
63
65
  rc1=filename(fref1,filepath,'disk','recfm=n');
64
66
  rc2=filename(fref2,filepath2,'disk','recfm=n');
65
67
  if fcopy(fref1,fref2) ne 0 then do;
66
- sysmsg=sysmsg();
68
+ msg=sysmsg();
67
69
  putlog "%str(ERR)OR: Unable to copy " filepath " to " filepath2;
68
- putlog sysmg=;
70
+ putlog msg=;
69
71
  end;
70
72
  end;
71
73
  rc=filename(fref1);
@@ -1,16 +1,22 @@
1
1
  /**
2
2
  @file
3
- @brief Converts every value in a dataset to it's formatted value
3
+ @brief Converts every value in a dataset to formatted value
4
4
  @details Converts every value to it's formatted value. All variables will
5
- become character, and will be in the same order.
5
+ become character, and will be in the same order as the original dataset.
6
+
7
+ Lengths will be adjusted according to the format lengths, where applicable.
6
8
 
7
9
  Usage:
8
10
 
9
11
  %mp_ds2fmtds(sashelp.cars,work.cars)
12
+ %mp_ds2fmtds(sashelp.vallopt,vw_vallopt)
10
13
 
11
14
  @param [in] libds The library.dataset to be converted
12
15
  @param [out] outds The dataset to create.
13
16
 
17
+ <h4> SAS Macros </h4>
18
+ @li mf_existds.sas
19
+
14
20
  <h4> Related Macros <h4>
15
21
  @li mp_jsonout.sas
16
22
 
@@ -22,8 +28,9 @@
22
28
  )/*/STORE SOURCE*/;
23
29
 
24
30
  /* validations */
25
- %if not %sysfunc(exist(&libds)) %then %do;
26
- %put %str(WARN)ING: &libds does not exist;
31
+
32
+ %if not %mf_existds(libds=&libds) %then %do;
33
+ %put %str(WARN)ING: &libds does not exist as either a VIEW or DATASET;
27
34
  %return;
28
35
  %end;
29
36
  %if %index(&libds,.)=0 %then %let libds=WORK.&libds;
@@ -116,6 +116,7 @@ data _null_;
116
116
  if _n_>&maxobs then stop;
117
117
  %end;
118
118
  length _____str $32767;
119
+ call missing(_____str);
119
120
  format _numeric_ best.;
120
121
  format _character_ ;
121
122
  %local i comma var vtype vfmt;
@@ -33,8 +33,8 @@
33
33
  @param [in] targetds The target dataset against which to verify the query
34
34
  @param [out] abort= (YES) If YES will call mp_abort.sas on any exceptions
35
35
  @param [out] outds= (work.mp_filtervalidate) Output dataset containing the
36
- error / warning message, if one exists. If this table contains any rows,
37
- there are problems!
36
+ err / warning message, if one exists. If this table contains any rows,
37
+ there are problems!
38
38
 
39
39
  <h4> SAS Macros </h4>
40
40
  @li mf_getuniquefileref.sas
@@ -48,17 +48,17 @@
48
48
  %let vw=%mf_getuniquename(prefix=mp_getconstraints_vw_);
49
49
  data &vw /view=&vw;
50
50
  set sashelp.vcncolu;
51
- where TABLE_CATALOG="&lib";
51
+ where table_catalog="&lib";
52
52
 
53
53
  /* use retain approach to reset the constraint order with each constraint */
54
54
  length tmp $1000;
55
55
  retain tmp;
56
56
  drop tmp;
57
- if tmp ne catx('|',libref,table_name,constraint_type,constraint_name) then do;
57
+ if tmp ne catx('|',table_catalog,table_name,constraint_name) then do;
58
58
  constraint_order=1;
59
59
  end;
60
60
  else constraint_order+1;
61
- tmp=catx('|',libref, table_name, constraint_type,constraint_name);
61
+ tmp=catx('|',table_catalog, table_name,constraint_name);
62
62
  run;
63
63
 
64
64
  /* must use SQL as proc datasets does not support length changes */
@@ -139,7 +139,7 @@ run;
139
139
  %let curds=%scan(&dsnlist,&x);
140
140
  data _null_;
141
141
  file &fref mod;
142
- length nm lab $1024 typ $20;
142
+ length lab $1024 typ $20;
143
143
  set &colinfo (where=(upcase(memname)="&curds")) end=last;
144
144
 
145
145
  if _n_=1 then do;
@@ -21,6 +21,7 @@
21
21
 
22
22
  @param [in] libds dataset to hash
23
23
  @param [in] salt= Provide a salt (could be, for instance, the dataset name)
24
+ @param [in] iftrue= A condition under which the macro should be executed.
24
25
  @param [out] outds= (work.mf_hashdataset) The output dataset to create. This
25
26
  will contain one column (hashkey) with one observation (a hex32.
26
27
  representation of the input hash)
@@ -35,10 +36,14 @@
35
36
  %macro mp_hashdataset(
36
37
  libds,
37
38
  outds=,
38
- salt=
39
+ salt=,
40
+ iftrue=%str(1=1)
39
41
  )/*/STORE SOURCE*/;
42
+
43
+ %if not(%eval(%unquote(&iftrue))) %then %return;
44
+
40
45
  %if %mf_getattrn(&libds,NLOBS)=0 %then %do;
41
- %put %str(WARN)ING: Dataset &libds is empty;, or is not a dataset;
46
+ %put %str(WARN)ING: Dataset &libds is empty, or is not a dataset;
42
47
  %end;
43
48
  %else %if %mf_getattrn(&libds,NLOBS)<0 %then %do;
44
49
  %put %str(ERR)OR: Dataset &libds is not a dataset;
package/base/mp_init.sas CHANGED
@@ -1,15 +1,25 @@
1
1
  /**
2
2
  @file
3
3
  @brief Initialise session with useful settings and variables
4
- @details Implements a set of recommended options for general SAS use. This
5
- macro is NOT used elsewhere within the core library (other than in tests),
6
- but it is used by the SASjs team when building web services for
7
- SAS-Powered applications elsewhere.
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.
8
7
 
9
- If you have a good idea for an option, setting, or useful global variable -
10
- feel free to [raise an issue](https://github.com/sasjs/core/issues/new)!
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).
11
13
 
12
- All global variables are prefixed with "SASJS_" (unless modfied with the
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
13
23
  prefix parameter).
14
24
 
15
25
  @param [in] prefix= (SASJS) The prefix to apply to the global macro variables
@@ -39,16 +49,17 @@
39
49
  autocorrect /* disallow mis-spelled procedure names */
40
50
  compress=CHAR /* default is none so ensure we have something! */
41
51
  datastmtchk=ALLKEYWORDS /* protection from overwriting input datasets */
42
- errorcheck=STRICT /* catch errors in libname/filename statements */
43
- fmterr /* ensure error when a format cannot be found */
44
- mergenoby=ERROR /*
45
- missing=. /* some sites change this which causes hard to detect errors */
52
+ %str(err)orcheck=STRICT /* catch errs in libname/filename statements */
53
+ fmterr /* ensure err when a format cannot be found */
54
+ mergenoby=%str(ERR)OR /* throw err when a merge has no BY variables */
55
+ missing=. /* changing this can cause hard to detect errs */
46
56
  noquotelenmax /* avoid warnings for long strings */
47
57
  noreplace /* avoid overwriting permanent datasets */
48
58
  ps=max /* reduce log size slightly */
49
59
  validmemname=COMPATIBLE /* avoid special characters etc in table names */
50
60
  validvarname=V7 /* avoid special characters etc in variable names */
51
- varlenchk=ERROR /* fail hard if truncation (data loss) can result */
61
+ varinitchk=%str(ERR)OR /* avoid data mistakes from variable name typos */
62
+ varlenchk=%str(ERR)OR /* fail hard if truncation (data loss) can result */
52
63
  ;
53
64
 
54
65
  %mend mp_init;
@@ -63,7 +63,7 @@
63
63
  %if &action=OPEN %then %do;
64
64
  options nobomfile;
65
65
  data _null_;file &jref encoding='utf-8';
66
- put '{"START_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '"';
66
+ put '{"PROCESSED_DTTM" : "' "%sysfunc(datetime(),E8601DT26.6)" '"';
67
67
  run;
68
68
  %end;
69
69
  %else %if (&action=ARR or &action=OBJ) %then %do;
@@ -239,7 +239,7 @@ run;
239
239
  %let abortme=1;
240
240
  %end;
241
241
 
242
- /* catch errors - mp_abort must be called outside of a logic block */
242
+ /* catch errs - mp_abort must be called outside of a logic block */
243
243
  %mp_abort(iftrue=(&abortme=1),
244
244
  msg=%superq(msg),
245
245
  mac=&sysmacroname
@@ -11,22 +11,28 @@
11
11
  Usage:
12
12
 
13
13
  %mp_searchdata(lib=sashelp, string=Jan)
14
- %mp_searchdata(lib=sashelp, numval=1)
14
+ %mp_searchdata(lib=sashelp, ds=bird, numval=1)
15
+ %mp_searchdata(lib=sashelp, ds=class, string=l,outobs=5)
15
16
 
16
17
 
17
18
  Outputs zero or more tables to an MPSEARCH library with specific records.
18
19
 
19
- @param lib= the libref to search (should be already assigned)
20
- @param ds= the dataset to search (leave blank to search entire library)
21
- @param string= the string value to search
22
- @param numval= the numeric value to search (must be exact)
23
- @param outloc= the directory in which to create the output datasets with
24
- matching rows. Will default to a subfolder in the WORK library.
25
- @param outobs= set to a positive integer to restrict the number of
20
+ @param [in] lib= The libref to search (should be already assigned)
21
+ @param [in] ds= The dataset to search (leave blank to search entire library)
22
+ @param [in] string= String value to search (case sensitive, can be partial)
23
+ @param [in] numval= Numeric value to search (must be exact)
24
+ @param [out] outloc= (0) Optionally specify the directory in which to
25
+ create the the output datasets with matching rows. By default it will
26
+ write them to a temporary subdirectory within the WORK folder.
27
+ @param [out] outlib= (MPSEARCH) Assign a different libref to the output
28
+ library containing the matching datasets / records
29
+ @param [in] outobs= set to a positive integer to restrict the number of
26
30
  observations
27
- @param filter_text= add a (valid) filter clause to further filter the results
31
+ @param [in] filter_text= (1=1) Add a (valid) filter clause to further filter
32
+ the results.
28
33
 
29
34
  <h4> SAS Macros </h4>
35
+ @li mf_getuniquename.sas
30
36
  @li mf_getvarlist.sas
31
37
  @li mf_getvartype.sas
32
38
  @li mf_mkdir.sas
@@ -36,11 +42,12 @@
36
42
  @author Allan Bowe
37
43
  **/
38
44
 
39
- %macro mp_searchdata(lib=sashelp
45
+ %macro mp_searchdata(lib=
40
46
  ,ds=
41
47
  ,string= /* the query will use a contains (?) operator */
42
48
  ,numval= /* numeric must match exactly */
43
- ,outloc=%sysfunc(pathname(work))/mpsearch
49
+ ,outloc=0
50
+ ,outlib=MPSEARCH
44
51
  ,outobs=-1
45
52
  ,filter_text=%str(1=1)
46
53
  )/*/STORE SOURCE*/;
@@ -57,8 +64,12 @@
57
64
  %if &string = %then %let type=N;
58
65
  %else %let type=C;
59
66
 
67
+ %if "&outloc"="0" %then %do;
68
+ %let outloc=%sysfunc(pathname(work))/%mf_getuniquename();
69
+ %end;
70
+
60
71
  %mf_mkdir(&outloc)
61
- libname mpsearch "&outloc";
72
+ libname &outlib "&outloc";
62
73
 
63
74
  /* get the list of tables in the library */
64
75
  proc sql noprint;
@@ -70,11 +81,6 @@ select distinct memname into: table_list separated by ' '
70
81
  %end;
71
82
  ;
72
83
  /* check that we have something to check */
73
- proc sql
74
- %if &outobs>-1 %then %do;
75
- outobs=&outobs
76
- %end;
77
- ;
78
84
  %if %length(&table_list)=0 %then %put library &lib contains no tables!;
79
85
  /* loop through each table */
80
86
  %else %do table_num=1 %to %sysfunc(countw(&table_list,%str( )));
@@ -85,10 +91,10 @@ proc sql
85
91
  %end;
86
92
  %else %do;
87
93
  %let check_tm=%sysfunc(datetime());
88
- /* build sql statement */
89
- create table mpsearch.&table as select * from &lib..&table
90
- where %unquote(&filter_text) and
91
- (0
94
+ /* prep input */
95
+ data &outlib..&table;
96
+ set &lib..&table;
97
+ where %unquote(&filter_text) and ( 0
92
98
  /* loop through columns */
93
99
  %do colnum=1 %to %sysfunc(countw(&vars,%str( )));
94
100
  %let col=%scan(&vars,&colnum,%str( ));
@@ -102,15 +108,20 @@ proc sql
102
108
  or ("&col"n = &numval)
103
109
  %end;
104
110
  %end;
105
- );
111
+ );
112
+ %if &outobs>-1 %then %do;
113
+ if _n_ > &outobs then stop;
114
+ %end;
115
+ run;
106
116
  %put Search query for &table took
107
117
  %sysevalf(%sysfunc(datetime())-&check_tm) seconds;
108
- %if &sqlrc ne 0 %then %do;
109
- %put %str(WAR)NING: SQLRC=&sqlrc when processing &table;
118
+ %if &syscc ne 0 %then %do;
119
+ %put %str(ERR)ROR: SYSCC=&syscc when processing &lib..&table;
110
120
  %return;
111
121
  %end;
112
- %if %mf_nobs(mpsearch.&table)=0 %then %do;
113
- drop table mpsearch.&table;
122
+ %if %mf_nobs(&outlib..&table)=0 %then %do;
123
+ proc sql;
124
+ drop table &outlib..&table;
114
125
  %end;
115
126
  %end;
116
127
  %end;
@@ -95,7 +95,7 @@ data _null_;
95
95
  put '%if &action=OPEN %then %do; ';
96
96
  put ' options nobomfile; ';
97
97
  put ' data _null_;file &jref encoding=''utf-8''; ';
98
- put ' put ''{"START_DTTM" : "'' "%sysfunc(datetime(),datetime20.3)" ''"''; ';
98
+ put ' put ''{"PROCESSED_DTTM" : "'' "%sysfunc(datetime(),E8601DT26.6)" ''"''; ';
99
99
  put ' run; ';
100
100
  put '%end; ';
101
101
  put '%else %if (&action=ARR or &action=OBJ) %then %do; ';
package/package.json CHANGED
@@ -38,5 +38,5 @@
38
38
  "dependencies": {
39
39
  "ts-loader": "^9.2.6"
40
40
  },
41
- "version": "2.56.0"
41
+ "version": "2.57.0"
42
42
  }
@@ -243,7 +243,7 @@ data _null_;
243
243
  put '%if &action=OPEN %then %do; ';
244
244
  put ' options nobomfile; ';
245
245
  put ' data _null_;file &jref encoding=''utf-8''; ';
246
- put ' put ''{"START_DTTM" : "'' "%sysfunc(datetime(),datetime20.3)" ''"''; ';
246
+ put ' put ''{"PROCESSED_DTTM" : "'' "%sysfunc(datetime(),E8601DT26.6)" ''"''; ';
247
247
  put ' run; ';
248
248
  put '%end; ';
249
249
  put '%else %if (&action=ARR or &action=OBJ) %then %do; ';
@@ -123,6 +123,7 @@ options noquotelenmax;
123
123
  libname &libref2 JSON fileref=&fname2;
124
124
  data &outds;
125
125
  length id $36 name $128 uri $64 type $32 description $256;
126
+ if _n_=1 then call missing (of _all_);
126
127
  set &libref2..items;
127
128
  run;
128
129
  filename &fname2 clear;
@@ -168,6 +168,7 @@ run;
168
168
  data &outds;
169
169
  format _program uri $128. state $32. stateDetails $32. timestamp datetime19.
170
170
  jobparams $32767.;
171
+ call missing (of _all_);
171
172
  stop;
172
173
  run;
173
174