@sasjs/core 3.9.2 → 3.11.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.
@@ -0,0 +1,119 @@
1
+ /**
2
+ @file
3
+ @brief Used to capture scope leakage of macro variables
4
+ @details A common 'difficult to detect' bug in macros is where a nested
5
+ macro over-writes variables in a higher level macro.
6
+
7
+ This assertion takes a snapshot of the macro variables before and after
8
+ a macro invocation. This makes it easy to detect whether any macro
9
+ variables were modified or changed.
10
+
11
+ Currently, the macro only checks for global scope variables. In the future
12
+ it may be extended to work at multiple levels of nesting.
13
+
14
+ If you would like this feature, feel free to contribute / raise an issue /
15
+ engage the SASjs team directly.
16
+
17
+ Example usage:
18
+
19
+ %mp_assertscope(SNAPSHOT)
20
+
21
+ %let oops=I did it again;
22
+
23
+ %mp_assertscope(COMPARE,
24
+ desc=Checking macro variables against previous snapshot
25
+ )
26
+
27
+ @param [in] action (SNAPSHOT) The action to take. Valid values:
28
+ @li SNAPSHOT - take a copy of the current macro variables
29
+ @li COMPARE - compare the current macro variables against previous values
30
+ @param [in] scope= (GLOBAL) The scope of the variables to be checked. This
31
+ corresponds to the values in the SCOPE column in `sashelp.vmacro`.
32
+ @param [in] desc= (Testing variable scope) The user provided test description
33
+ @param [in,out] scopeds= (work.mp_assertscope) The dataset to contain the
34
+ scope snapshot
35
+ @param [out] outds= (work.test_results) The output dataset to contain the
36
+ results. If it does not exist, it will be created, with the following format:
37
+ |TEST_DESCRIPTION:$256|TEST_RESULT:$4|TEST_COMMENTS:$256|
38
+ |---|---|---|
39
+ |User Provided description|PASS|No out of scope variables created or modified|
40
+
41
+ <h4> Related Macros </h4>
42
+ @li mp_assert.sas
43
+ @li mp_assertcols.sas
44
+ @li mp_assertcolvals.sas
45
+ @li mp_assertdsobs.sas
46
+ @li mp_assertscope.test.sas
47
+
48
+ @version 9.2
49
+ @author Allan Bowe
50
+
51
+ **/
52
+
53
+ %macro mp_assertscope(action,
54
+ desc=0,
55
+ scope=GLOBAL,
56
+ scopeds=work.mp_assertscope,
57
+ outds=work.test_results
58
+ )/*/STORE SOURCE*/;
59
+ %local ds test_result test_comments del add mod;
60
+
61
+ /* get current variables */
62
+ %if &action=SNAPSHOT %then %do;
63
+ proc sql;
64
+ create table &scopeds as
65
+ select name,offset,value
66
+ from dictionary.macros
67
+ where scope="&scope"
68
+ order by name,offset;
69
+ %end;
70
+ %else %if &action=COMPARE %then %do;
71
+
72
+ proc sql;
73
+ create table _data_ as
74
+ select name,offset,value
75
+ from dictionary.macros
76
+ where scope="&scope"
77
+ order by name,offset;
78
+
79
+ %let ds=&syslast;
80
+
81
+ proc compare base=&scopeds compare=&ds;
82
+ run;
83
+
84
+ %if &sysinfo=0 %then %do;
85
+ %let test_result=PASS;
86
+ %let test_comments=&scope Variables Unmodified;
87
+ %end;
88
+ %else %do;
89
+ proc sql noprint undo_policy=none;
90
+ select distinct name into: del separated by ' ' from &scopeds
91
+ where name not in (select name from &ds);
92
+ select distinct name into: add separated by ' ' from &ds
93
+ where name not in (select name from &scopeds);
94
+ select distinct a.name into: mod separated by ' '
95
+ from &scopeds a
96
+ inner join &ds b
97
+ on a.name=b.name
98
+ and a.offset=b.offset
99
+ where a.value ne b.value;
100
+ %let test_result=FAIL;
101
+ %let test_comments=%str(Mod:(&mod) Add:(&add) Del:(&del));
102
+ %end;
103
+
104
+
105
+ data ;
106
+ length test_description $256 test_result $4 test_comments $256;
107
+ test_description=symget('desc');
108
+ test_comments=symget('test_comments');
109
+ test_result=symget('test_result');
110
+ run;
111
+
112
+ %let ds=&syslast;
113
+ proc append base=&outds data=&ds;
114
+ run;
115
+ proc sql;
116
+ drop table &ds;
117
+ %end;
118
+
119
+ %mend mp_assertscope;
@@ -198,18 +198,23 @@ run;
198
198
  * The above transpose can mean that some updates create additional columns.
199
199
  * This necessitates the occasional use of datastep over proc append.
200
200
  */
201
- %local basevars appvars usedatastep;
202
- %let basevars=%mf_getvarlist(&outds);
203
- %let appvars=%mf_getvarlist(&out_ds);
204
- %let newvars=%length(%mf_wordsinstr1butnotstr2(Str1=&appvars,Str2=&basevars));
205
-
206
- %if %mf_existds(&outds) and &newvars>0 %then %do;
207
- data &outds;
208
- set &outds &out_ds;
209
- run;
201
+ %if %mf_existds(&outds) %then %do;
202
+ %local basevars appvars newvars;
203
+ %let basevars=%mf_getvarlist(&outds);
204
+ %let appvars=%mf_getvarlist(&out_ds);
205
+ %let newvars=%length(%mf_wordsinstr1butnotstr2(Str1=&appvars,Str2=&basevars));
206
+ %if &newvars>0 %then %do;
207
+ data &outds;
208
+ set &outds &out_ds;
209
+ run;
210
+ %end;
211
+ %else %do;
212
+ proc append base=&outds data=&out_ds force nowarn;
213
+ run;
214
+ %end;
210
215
  %end;
211
216
  %else %do;
212
- proc append base=&outds data=&out_ds force nowarn;
217
+ proc append base=&outds data=&out_ds;
213
218
  run;
214
219
  %end;
215
220
 
@@ -139,8 +139,9 @@ create table datalines1 as
139
139
  /**
140
140
  Due to long decimals cannot use best. format
141
141
  So - use bestd. format and then use character functions to strip trailing
142
- zeros, if NOT an integer!!
143
- resolved code = ifc(int(VARIABLE)=VARIABLE
142
+ zeros, if NOT an integer or missing!! Cannot use int() as it upsets
143
+ note2err when there are missings.
144
+ resolved code = ifc( mod(coalesce(VARIABLE,0),1)=0
144
145
  ,put(VARIABLE,best32.)
145
146
  ,substrn(put(VARIABLE,bestd32.),1
146
147
  ,findc(put(VARIABLE,bestd32.),'0','TBK')));
@@ -151,7 +152,7 @@ data datalines_2;
151
152
  set datalines1 (where=(upcase(name) not in
152
153
  ('PROCESSED_DTTM','VALID_FROM_DTTM','VALID_TO_DTTM')));
153
154
  if type='num' then dataline=
154
- cats('ifc(int(',name,')=',name,'
155
+ cats('ifc(mod(coalesce(',name,',0),1)=0
155
156
  ,put(',name,',best32.-l)
156
157
  ,substrn(put(',name,',bestd32.-l),1
157
158
  ,findc(put(',name,',bestd32.-l),"0","TBK")))');
@@ -41,7 +41,7 @@ data _null_;
41
41
  dsid=open("&ds.","i");
42
42
  num=attrn(dsid,"nvars");
43
43
  do i=1 to num;
44
- header = trim(left(coalescec(varlabel(dsid,i),varname(dsid,i))));
44
+ header = cats(coalescec(varlabel(dsid,i),varname(dsid,i)));
45
45
  put header @;
46
46
  end;
47
47
  rc=close(dsid);
@@ -109,7 +109,7 @@ data &outds;
109
109
  output;
110
110
  end;
111
111
  if mod(SUBGROUP_ID,1) ne 0 then do;
112
- REASON_CD='SUBGROUP_ID should be integer, not '!!left(subgroup_id);
112
+ REASON_CD='SUBGROUP_ID should be integer, not '!!cats(subgroup_id);
113
113
  putlog REASON_CD= SUBGROUP_ID=;
114
114
  call symputx('reason_cd',reason_cd,'l');
115
115
  call symputx('nobs',_n_,'l');
@@ -127,7 +127,7 @@ data &outds;
127
127
  if OPERATOR_NM not in
128
128
  ('=','>','<','<=','>=','BETWEEN','IN','NOT IN','NE','CONTAINS')
129
129
  then do;
130
- REASON_CD='Invalid OPERATOR_NM: '!!left(OPERATOR_NM);
130
+ REASON_CD='Invalid OPERATOR_NM: '!!cats(OPERATOR_NM);
131
131
  putlog REASON_CD= OPERATOR_NM=;
132
132
  call symputx('reason_cd',reason_cd,'l');
133
133
  call symputx('nobs',_n_,'l');
@@ -158,7 +158,7 @@ run;
158
158
  lab=" label="!!cats("'",tranwrd(label,"'","''"),"'");
159
159
  if notnull='yes' then notnul=' not null';
160
160
  if type='char' then typ=cats('char(',length,')');
161
- else if length ne 8 then typ='num length='!!left(length);
161
+ else if length ne 8 then typ='num length='!!cats(length);
162
162
  else typ='num';
163
163
  put name typ fmt notnul lab;
164
164
  run;
package/base/mp_init.sas CHANGED
@@ -51,6 +51,7 @@
51
51
  noautocorrect /* disallow misspelled procedure names */
52
52
  compress=CHAR /* default is none so ensure we have something! */
53
53
  datastmtchk=ALLKEYWORDS /* protection from overwriting input datasets */
54
+ dsoptions=note2err /* undocumented - convert bad NOTEs to ERRs */
54
55
  %str(err)orcheck=STRICT /* catch errs in libname/filename statements */
55
56
  fmterr /* ensure err when a format cannot be found */
56
57
  mergenoby=%str(ERR)OR /* throw err when a merge has no BY variables */
@@ -76,7 +76,7 @@
76
76
  else do;
77
77
  x+1;
78
78
  call symputx(name,quote(cats(value)),'l');
79
- call symputx('pval'!!left(x),name,'l');
79
+ call symputx(cats('pval',x),name,'l');
80
80
  call symputx('pcnt',x,'l');
81
81
  end;
82
82
  run;
@@ -48,9 +48,11 @@
48
48
  %let tempcol=%mf_getuniquename();
49
49
 
50
50
  %if &rule=ISINT %then %do;
51
- &tempcol=input(&incol,?? best32.);
52
51
  &outcol=0;
53
- if not missing(&tempcol) then if mod(&incol,1)=0 then &outcol=1;
52
+ if not missing(&incol) then do;
53
+ &tempcol=input(&incol,?? best32.);
54
+ if not missing(&tempcol) then if mod(&tempcol,1)=0 then &outcol=1;
55
+ end;
54
56
  drop &tempcol;
55
57
  %end;
56
58
  %else %if &rule=ISNUM %then %do;
@@ -69,7 +69,7 @@
69
69
  %if %mf_existfunction(stpsrv_header)=1 %then %return;
70
70
 
71
71
  %if &wrap=YES %then %do;
72
- proc fcmp outcat=&lib..&cat..&pkg;
72
+ proc fcmp outlib=&lib..&cat..&pkg;
73
73
  %end;
74
74
 
75
75
  function stpsrv_header(name $, value $);
@@ -49,7 +49,7 @@
49
49
  )/*/STORE SOURCE*/;
50
50
 
51
51
  %if &wrap=YES %then %do;
52
- proc fcmp outcat=&lib..&cat..&pkg;
52
+ proc fcmp outlib=&lib..&cat..&pkg;
53
53
  %end;
54
54
 
55
55
  function mcf_string2file(filepath $, string $, mode $);
@@ -383,7 +383,7 @@ data _null_;
383
383
  put ' set &tempds; ';
384
384
  put ' if not (upcase(name) =:"DATA"); /* ignore temp datasets */ ';
385
385
  put ' i+1; ';
386
- put ' call symputx(''wt''!!left(i),name,''l''); ';
386
+ put ' call symputx(cats(''wt'',i),name,''l''); ';
387
387
  put ' call symputx(''wtcnt'',i,''l''); ';
388
388
  put ' data _null_; file &fref mod encoding=''utf-8''; ';
389
389
  put ' put ",""WORK"":{"; ';
@@ -427,6 +427,7 @@ data _null_;
427
427
  put ' put '',"SYSVLONG" : '' sysvlong; ';
428
428
  put ' put ",""SYSWARNINGTEXT"" : ""&syswarningtext"" "; ';
429
429
  put ' put '',"END_DTTM" : "'' "%sysfunc(datetime(),datetime20.3)" ''" ''; ';
430
+ put ' length memsize $32; ';
430
431
  put ' memsize="%sysfunc(INPUTN(%sysfunc(getoption(memsize)), best.),sizekmg.)"; ';
431
432
  put ' memsize=quote(cats(memsize)); ';
432
433
  put ' put '',"MEMSIZE" : '' memsize; ';
@@ -35,7 +35,7 @@ data _null_;
35
35
  set repos;
36
36
  where repositorytype in('CUSTOM','FOUNDATION');
37
37
  keep id name ;
38
- call symputx('repo'!!left(_n_),name,'l');
38
+ call symputx(cats('repo',_n_),name,'l');
39
39
  call symputx('repocnt',_n_,'l');
40
40
  run;
41
41
 
@@ -122,7 +122,7 @@
122
122
  set &tempds;
123
123
  if not (upcase(name) =:"DATA"); /* ignore temp datasets */
124
124
  i+1;
125
- call symputx('wt'!!left(i),name,'l');
125
+ call symputx(cats('wt',i),name,'l');
126
126
  call symputx('wtcnt',i,'l');
127
127
  data _null_; file &fref mod encoding='utf-8';
128
128
  put ",""WORK"":{";
@@ -166,6 +166,7 @@
166
166
  put ',"SYSVLONG" : ' sysvlong;
167
167
  put ",""SYSWARNINGTEXT"" : ""&syswarningtext"" ";
168
168
  put ',"END_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '" ';
169
+ length memsize $32;
169
170
  memsize="%sysfunc(INPUTN(%sysfunc(getoption(memsize)), best.),sizekmg.)";
170
171
  memsize=quote(cats(memsize));
171
172
  put ',"MEMSIZE" : ' memsize;
package/package.json CHANGED
@@ -33,10 +33,7 @@
33
33
  "prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true"
34
34
  },
35
35
  "devDependencies": {
36
- "@sasjs/cli": "^3.4.1"
36
+ "@sasjs/cli": "3.6.0"
37
37
  },
38
- "dependencies": {
39
- "ts-loader": "^9.2.6"
40
- },
41
- "version": "3.9.2"
38
+ "version": "3.11.1"
42
39
  }
@@ -114,7 +114,7 @@
114
114
  set &tempds;
115
115
  if not (upcase(name) =:"DATA"); /* ignore temp datasets */
116
116
  i+1;
117
- call symputx('wt'!!left(i),name,'l');
117
+ call symputx(cats('wt',i),name,'l');
118
118
  call symputx('wtcnt',i,'l');
119
119
  data _null_; file &fref mod encoding='utf-8' termstr=lf;
120
120
  put ",""WORK"":{";
@@ -165,6 +165,7 @@
165
165
  length autoexec $512;
166
166
  autoexec=quote(urlencode(trim(getoption('autoexec'))));
167
167
  put ',"AUTOEXEC" : ' autoexec;
168
+ length memsize $32;
168
169
  memsize="%sysfunc(INPUTN(%sysfunc(getoption(memsize)), best.),sizekmg.)";
169
170
  memsize=quote(cats(memsize));
170
171
  put ',"MEMSIZE" : ' memsize;
@@ -589,8 +589,8 @@ data _null_;
589
589
  put ' set &tempds; ';
590
590
  put ' if not (upcase(name) =:"DATA"); /* ignore temp datasets */ ';
591
591
  put ' i+1; ';
592
- put ' call symputx(''wt''!!left(i),name); ';
593
- put ' call symputx(''wtcnt'',i); ';
592
+ put ' call symputx(cats(''wt'',i),name,''l''); ';
593
+ put ' call symputx(''wtcnt'',i,''l''); ';
594
594
  put ' data _null_; file &fref mod; put ",""WORK"":{"; ';
595
595
  put ' %do i=1 %to &wtcnt; ';
596
596
  put ' %let wt=&&wt&i; ';
@@ -628,6 +628,7 @@ data _null_;
628
628
  put ' put '',"SYSVLONG" : '' sysvlong; ';
629
629
  put ' put ",""SYSWARNINGTEXT"" : ""&syswarningtext"" "; ';
630
630
  put ' put '',"END_DTTM" : "'' "%sysfunc(datetime(),datetime20.3)" ''" ''; ';
631
+ put ' length memsize $32; ';
631
632
  put ' memsize="%sysfunc(INPUTN(%sysfunc(getoption(memsize)), best.),sizekmg.)"; ';
632
633
  put ' memsize=quote(cats(memsize)); ';
633
634
  put ' put '',"MEMSIZE" : '' memsize; ';
@@ -272,7 +272,7 @@ data;run;%let jdswaitfor=&syslast;
272
272
  data _null_;
273
273
  infile &jfref lrecl=32767;
274
274
  input;
275
- jparams='jparams'!!left(symget('jid'));
275
+ jparams=cats('jparams',symget('jid'));
276
276
  call symputx(jparams,substr(_infile_,3,length(_infile_)-4));
277
277
  run;
278
278
  %local jobuid&jid;
@@ -187,8 +187,8 @@
187
187
  set &tempds;
188
188
  if not (upcase(name) =:"DATA"); /* ignore temp datasets */
189
189
  i+1;
190
- call symputx('wt'!!left(i),name);
191
- call symputx('wtcnt',i);
190
+ call symputx(cats('wt',i),name,'l');
191
+ call symputx('wtcnt',i,'l');
192
192
  data _null_; file &fref mod; put ",""WORK"":{";
193
193
  %do i=1 %to &wtcnt;
194
194
  %let wt=&&wt&i;
@@ -226,6 +226,7 @@
226
226
  put ',"SYSVLONG" : ' sysvlong;
227
227
  put ",""SYSWARNINGTEXT"" : ""&syswarningtext"" ";
228
228
  put ',"END_DTTM" : "' "%sysfunc(datetime(),datetime20.3)" '" ';
229
+ length memsize $32;
229
230
  memsize="%sysfunc(INPUTN(%sysfunc(getoption(memsize)), best.),sizekmg.)";
230
231
  memsize=quote(cats(memsize));
231
232
  put ',"MEMSIZE" : ' memsize;