@sasjs/core 4.45.11 → 4.46.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/.sasjslint +1 -0
- package/base/mf_existvar.sas +8 -4
- package/base/mp_aligndecimal.sas +94 -0
- package/base/mp_assertcolvals.sas +8 -4
- package/base/mp_cntlout.sas +5 -4
- package/base/mp_loadformat.sas +33 -12
- package/base/mp_lockanytable.sas +1 -1
- package/ddl/mddl_sas_cntlout.sas +8 -3
- package/package.json +1 -1
package/.sasjslint
CHANGED
package/base/mf_existvar.sas
CHANGED
|
@@ -25,13 +25,17 @@
|
|
|
25
25
|
%local dsid rc;
|
|
26
26
|
%let dsid=%sysfunc(open(&libds,is));
|
|
27
27
|
|
|
28
|
-
%if &dsid=0
|
|
28
|
+
%if &dsid=0 %then %do;
|
|
29
29
|
%put %sysfunc(sysmsg());
|
|
30
|
-
|
|
30
|
+
0
|
|
31
|
+
%end;
|
|
32
|
+
%else %if %length(&var)=0 %then %do;
|
|
33
|
+
0
|
|
34
|
+
%let rc=%sysfunc(close(&dsid));
|
|
31
35
|
%end;
|
|
32
36
|
%else %do;
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
%sysfunc(varnum(&dsid,&var))
|
|
38
|
+
%let rc=%sysfunc(close(&dsid));
|
|
35
39
|
%end;
|
|
36
40
|
|
|
37
41
|
%mend mf_existvar;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Apply leading blanks to align numbers vertically in a char variable
|
|
4
|
+
@details This is particularly useful when storing numbers (as character) that
|
|
5
|
+
need to be sorted.
|
|
6
|
+
|
|
7
|
+
It works by splitting the number left and right of the decimal place, and
|
|
8
|
+
aligning it accordingly. A temporary variable is created as part of this
|
|
9
|
+
process (which is automatically dropped)
|
|
10
|
+
|
|
11
|
+
The macro can be used only in data step, eg as follows:
|
|
12
|
+
|
|
13
|
+
data _null_;
|
|
14
|
+
length myvar $50;
|
|
15
|
+
do i=1 to 1000 by 50;
|
|
16
|
+
if mod(i,2)=0 then j=ranuni(0)*i*100;
|
|
17
|
+
else j=i*100;
|
|
18
|
+
|
|
19
|
+
%mp_aligndecimal(myvar,width=7)
|
|
20
|
+
|
|
21
|
+
leading_spaces=length(myvar)-length(cats(myvar));
|
|
22
|
+
putlog +leading_spaces myvar;
|
|
23
|
+
end;
|
|
24
|
+
run;
|
|
25
|
+
|
|
26
|
+
The generated code will look something like this:
|
|
27
|
+
|
|
28
|
+
length aligndp4e49996 $7;
|
|
29
|
+
if index(myvar,'.') then do;
|
|
30
|
+
aligndp4e49996=cats(scan(myvar,1,'.'));
|
|
31
|
+
aligndp4e49996=right(aligndp4e49996);
|
|
32
|
+
myvar=aligndp4e49996!!'.'!!cats(scan(myvar,2,'.'));
|
|
33
|
+
end;
|
|
34
|
+
else do;
|
|
35
|
+
aligndp4e49996=myvar;
|
|
36
|
+
aligndp4e49996=right(aligndp4e49996);
|
|
37
|
+
myvar=aligndp4e49996;
|
|
38
|
+
end;
|
|
39
|
+
|
|
40
|
+
Results (myvar variable):
|
|
41
|
+
|
|
42
|
+
0.7683559324
|
|
43
|
+
122.8232796
|
|
44
|
+
99419.50552
|
|
45
|
+
42938.5143414
|
|
46
|
+
763.3799189
|
|
47
|
+
15170.606073
|
|
48
|
+
15083.285773
|
|
49
|
+
85443.198707
|
|
50
|
+
2022999.2251
|
|
51
|
+
12038.658867
|
|
52
|
+
1350582.6734
|
|
53
|
+
52777.258221
|
|
54
|
+
11723.347628
|
|
55
|
+
33101.268376
|
|
56
|
+
6181622.8603
|
|
57
|
+
7390614.0669
|
|
58
|
+
73384.537893
|
|
59
|
+
1788362.1016
|
|
60
|
+
2774586.2219
|
|
61
|
+
7998580.8415
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@param var The (data step) variable to create
|
|
65
|
+
@param width= (8) The number of characters BEFORE the decimal point
|
|
66
|
+
|
|
67
|
+
<h4> SAS Macros </h4>
|
|
68
|
+
@li mf_getuniquename.sas
|
|
69
|
+
|
|
70
|
+
<h4> Related Programs </h4>
|
|
71
|
+
@li mp_aligndecimal.test.sas
|
|
72
|
+
|
|
73
|
+
@version 9.2
|
|
74
|
+
@author Allan Bowe
|
|
75
|
+
**/
|
|
76
|
+
|
|
77
|
+
%macro mp_aligndecimal(var,width=8);
|
|
78
|
+
|
|
79
|
+
%local tmpvar;
|
|
80
|
+
%let tmpvar=%mf_getuniquename(prefix=aligndp);
|
|
81
|
+
length &tmpvar $&width;
|
|
82
|
+
if index(&var,'.') then do;
|
|
83
|
+
&tmpvar=cats(scan(&var,1,'.'));
|
|
84
|
+
&tmpvar=right(&tmpvar);
|
|
85
|
+
&var=&tmpvar!!'.'!!cats(scan(&var,2,'.'));
|
|
86
|
+
end;
|
|
87
|
+
else do;
|
|
88
|
+
&tmpvar=cats(&var);
|
|
89
|
+
&tmpvar=right(&tmpvar);
|
|
90
|
+
&var=&tmpvar;
|
|
91
|
+
end;
|
|
92
|
+
drop &tmpvar;
|
|
93
|
+
|
|
94
|
+
%mend mp_aligndecimal;
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
@param [in] test= (ALLVALS) The test to apply. Valid values are:
|
|
43
43
|
@li ALLVALS - Test is a PASS if ALL values have a match in checkvals
|
|
44
44
|
@li ANYVAL - Test is a PASS if at least 1 value has a match in checkvals
|
|
45
|
+
@li NOVAL - Test is a PASS if there are NO matches in checkvals
|
|
45
46
|
@param [out] outds= (work.test_results) The output dataset to contain the
|
|
46
47
|
results. If it does not exist, it will be created, with the following format:
|
|
47
48
|
|TEST_DESCRIPTION:$256|TEST_RESULT:$4|TEST_COMMENTS:$256|
|
|
@@ -97,7 +98,7 @@
|
|
|
97
98
|
|
|
98
99
|
%let test=%upcase(&test);
|
|
99
100
|
|
|
100
|
-
%if &test ne ALLVALS and &test ne ANYVAL %then %do;
|
|
101
|
+
%if &test ne ALLVALS and &test ne ANYVAL and &test ne NOVAL %then %do;
|
|
101
102
|
%mp_abort(
|
|
102
103
|
mac=&sysmacroname,
|
|
103
104
|
msg=%str(Invalid test - &test)
|
|
@@ -108,12 +109,12 @@
|
|
|
108
109
|
%let result=-1;
|
|
109
110
|
%let orig=-1;
|
|
110
111
|
proc sql noprint;
|
|
111
|
-
select count(*) into: result
|
|
112
|
+
select count(*) into: result trimmed
|
|
112
113
|
from &lib..&ds
|
|
113
114
|
where &col not in (
|
|
114
115
|
select &ccol from &clib..&cds
|
|
115
116
|
);
|
|
116
|
-
select count(*) into: orig from &lib..&ds;
|
|
117
|
+
select count(*) into: orig trimmed from &lib..&ds;
|
|
117
118
|
quit;
|
|
118
119
|
|
|
119
120
|
%local notfound tmp1 tmp2;
|
|
@@ -145,7 +146,7 @@
|
|
|
145
146
|
length test_description $256 test_result $4 test_comments $256;
|
|
146
147
|
test_description=symget('desc');
|
|
147
148
|
test_result='FAIL';
|
|
148
|
-
test_comments="&sysmacroname: &lib..&ds..&col has &result values "
|
|
149
|
+
test_comments="&sysmacroname: &lib..&ds..&col has &result/&orig values "
|
|
149
150
|
!!"not in &clib..&cds..&ccol.. First 10 vals:"!!symget('notfound');
|
|
150
151
|
%if &test=ANYVAL %then %do;
|
|
151
152
|
if &result < &orig then test_result='PASS';
|
|
@@ -153,6 +154,9 @@
|
|
|
153
154
|
%else %if &test=ALLVALS %then %do;
|
|
154
155
|
if &result=0 then test_result='PASS';
|
|
155
156
|
%end;
|
|
157
|
+
%else %if &test=NOVAL %then %do;
|
|
158
|
+
if &result=&orig then test_result='PASS';
|
|
159
|
+
%end;
|
|
156
160
|
%else %do;
|
|
157
161
|
test_comments="&sysmacroname: Unsatisfied test condition - &test";
|
|
158
162
|
%end;
|
package/base/mp_cntlout.sas
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
<h4> Related Macros </h4>
|
|
30
30
|
@li mf_getvarformat.sas
|
|
31
|
+
@li mp_aligndecimal.sas
|
|
31
32
|
@li mp_getformats.sas
|
|
32
33
|
@li mp_loadformat.sas
|
|
33
34
|
@li mp_ds2fmtds.sas
|
|
@@ -69,13 +70,13 @@ run;
|
|
|
69
70
|
data &cntlout;
|
|
70
71
|
if 0 then set &ddlds;
|
|
71
72
|
set &cntlds;
|
|
72
|
-
if type
|
|
73
|
-
start=
|
|
74
|
-
end=
|
|
73
|
+
if type in ("I","N") then do; /* numeric (in)format */
|
|
74
|
+
%mp_aligndecimal(start,width=16)
|
|
75
|
+
%mp_aligndecimal(end,width=16)
|
|
75
76
|
end;
|
|
76
77
|
run;
|
|
77
78
|
proc sort;
|
|
78
|
-
by fmtname start;
|
|
79
|
+
by type fmtname start;
|
|
79
80
|
run;
|
|
80
81
|
|
|
81
82
|
proc sql;
|
package/base/mp_loadformat.sas
CHANGED
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
<h4> Related Macros </h4>
|
|
46
46
|
@li mddl_dc_difftable.sas
|
|
47
47
|
@li mddl_dc_locktable.sas
|
|
48
|
+
@li mp_aligndecimal.sas
|
|
48
49
|
@li mp_loadformat.test.sas
|
|
49
50
|
@li mp_lockanytable.sas
|
|
50
51
|
@li mp_stackdiffs.sas
|
|
@@ -134,7 +135,16 @@ run;
|
|
|
134
135
|
* First, extract only relevant formats from the catalog
|
|
135
136
|
*/
|
|
136
137
|
proc sql noprint;
|
|
137
|
-
select distinct
|
|
138
|
+
select distinct
|
|
139
|
+
case
|
|
140
|
+
when type='N' then upcase(fmtname)
|
|
141
|
+
when type='C' then cats('$',upcase(fmtname))
|
|
142
|
+
when type='I' then cats('@',upcase(fmtname))
|
|
143
|
+
when type='J' then cats('@$',upcase(fmtname))
|
|
144
|
+
else "&sysmacroname:UNHANDLED"
|
|
145
|
+
end
|
|
146
|
+
into: fmtlist separated by ' '
|
|
147
|
+
from &libds;
|
|
138
148
|
|
|
139
149
|
%mp_cntlout(libcat=&libcat,fmtlist=&fmtlist,cntlout=&base_fmts)
|
|
140
150
|
|
|
@@ -146,16 +156,24 @@ select distinct upcase(fmtname) into: fmtlist separated by ' ' from &libds;
|
|
|
146
156
|
data &inlibds;
|
|
147
157
|
length &delete_col $3;
|
|
148
158
|
if 0 then set &template;
|
|
159
|
+
length start end $10000;
|
|
149
160
|
set &libds;
|
|
150
161
|
if &delete_col='' then &delete_col='No';
|
|
151
162
|
fmtname=upcase(fmtname);
|
|
163
|
+
type=upcase(type);
|
|
152
164
|
if missing(type) then do;
|
|
153
|
-
if substr(fmtname,1,1)='
|
|
154
|
-
|
|
165
|
+
if substr(fmtname,1,1)='@' then do;
|
|
166
|
+
if substr(fmtname,2,1)='$' then type='J';
|
|
167
|
+
else type='I';
|
|
168
|
+
end;
|
|
169
|
+
else do;
|
|
170
|
+
if substr(fmtname,1,1)='$' then type='C';
|
|
171
|
+
else type='N';
|
|
172
|
+
end;
|
|
155
173
|
end;
|
|
156
|
-
if type
|
|
157
|
-
start=
|
|
158
|
-
end=
|
|
174
|
+
if type in ('N','I') then do;
|
|
175
|
+
%mp_aligndecimal(start,width=16)
|
|
176
|
+
%mp_aligndecimal(end,width=16)
|
|
159
177
|
end;
|
|
160
178
|
run;
|
|
161
179
|
|
|
@@ -169,9 +187,10 @@ create table &outds_add(drop=&delete_col) as
|
|
|
169
187
|
left join &base_fmts b
|
|
170
188
|
on a.fmtname=b.fmtname
|
|
171
189
|
and a.start=b.start
|
|
190
|
+
and a.type=b.type
|
|
172
191
|
where b.fmtname is null
|
|
173
192
|
and upcase(a.&delete_col) ne "YES"
|
|
174
|
-
order by fmtname, start
|
|
193
|
+
order by type, fmtname, start;
|
|
175
194
|
|
|
176
195
|
/**
|
|
177
196
|
* Identify deleted records
|
|
@@ -182,8 +201,9 @@ create table &outds_del(drop=&delete_col) as
|
|
|
182
201
|
inner join &base_fmts b
|
|
183
202
|
on a.fmtname=b.fmtname
|
|
184
203
|
and a.start=b.start
|
|
204
|
+
and a.type=b.type
|
|
185
205
|
where upcase(a.&delete_col)="YES"
|
|
186
|
-
order by fmtname, start;
|
|
206
|
+
order by type, fmtname, start;
|
|
187
207
|
|
|
188
208
|
/**
|
|
189
209
|
* Identify modified records
|
|
@@ -194,8 +214,9 @@ create table &outds_mod (drop=&delete_col) as
|
|
|
194
214
|
inner join &base_fmts b
|
|
195
215
|
on a.fmtname=b.fmtname
|
|
196
216
|
and a.start=b.start
|
|
217
|
+
and a.type=b.type
|
|
197
218
|
where upcase(a.&delete_col) ne "YES"
|
|
198
|
-
order by fmtname, start;
|
|
219
|
+
order by type, fmtname, start;
|
|
199
220
|
|
|
200
221
|
options ibufsize=&ibufsize;
|
|
201
222
|
|
|
@@ -212,13 +233,13 @@ options ibufsize=&ibufsize;
|
|
|
212
233
|
&outds_add(in=add)
|
|
213
234
|
&outds_del(in=del);
|
|
214
235
|
if not del and not mod;
|
|
215
|
-
by fmtname start;
|
|
236
|
+
by type fmtname start;
|
|
216
237
|
run;
|
|
217
238
|
data &stagedata;
|
|
218
239
|
set &ds1 &outds_mod;
|
|
219
240
|
run;
|
|
220
241
|
proc sort;
|
|
221
|
-
by fmtname start;
|
|
242
|
+
by type fmtname start;
|
|
222
243
|
run;
|
|
223
244
|
%end;
|
|
224
245
|
/* mp abort needs to run outside of conditional blocks */
|
|
@@ -266,7 +287,7 @@ options ibufsize=&ibufsize;
|
|
|
266
287
|
|
|
267
288
|
%mp_storediffs(&libcat-FC
|
|
268
289
|
,&base_fmts
|
|
269
|
-
,FMTNAME START
|
|
290
|
+
,TYPE FMTNAME START
|
|
270
291
|
,delds=&outds_del
|
|
271
292
|
,modds=&outds_mod
|
|
272
293
|
,appds=&outds_add
|
package/base/mp_lockanytable.sas
CHANGED
|
@@ -167,7 +167,7 @@ run;
|
|
|
167
167
|
data _null_;
|
|
168
168
|
putlog 'NOTE-' / 'NOTE-';
|
|
169
169
|
putlog "NOTE- &sysmacroname: table locked, waiting "@;
|
|
170
|
-
putlog "%sysfunc(sleep(&
|
|
170
|
+
putlog "%sysfunc(sleep(&loop_secs)) seconds.. ";
|
|
171
171
|
putlog "NOTE- (iteration &x of &loops)";
|
|
172
172
|
putlog 'NOTE-' / 'NOTE-';
|
|
173
173
|
run;
|
package/ddl/mddl_sas_cntlout.sas
CHANGED
|
@@ -12,14 +12,20 @@
|
|
|
12
12
|
|
|
13
13
|
proc sql;
|
|
14
14
|
create table &libds(
|
|
15
|
-
|
|
15
|
+
TYPE char(1) label='Type of format'
|
|
16
|
+
,FMTNAME char(32) label='Format name'
|
|
16
17
|
/*
|
|
17
18
|
to accommodate larger START values, mp_loadformat.sas will need the
|
|
18
19
|
SQL dependency removed (proc sql needs to accommodate 3 index values in
|
|
19
20
|
a 32767 ibufsize limit)
|
|
20
21
|
*/
|
|
21
22
|
,START char(10000) label='Starting value for format'
|
|
22
|
-
|
|
23
|
+
/*
|
|
24
|
+
Keep lengths of START and END the same to avoid this err:
|
|
25
|
+
"Start is greater than end: -<."
|
|
26
|
+
Similar usage note: https://support.sas.com/kb/69/330.html
|
|
27
|
+
*/
|
|
28
|
+
,END char(10000) label='Ending value for format'
|
|
23
29
|
,LABEL char(32767) label='Format value label'
|
|
24
30
|
,MIN num length=3 label='Minimum length'
|
|
25
31
|
,MAX num length=3 label='Maximum length'
|
|
@@ -30,7 +36,6 @@ create table &libds(
|
|
|
30
36
|
,MULT num label='Multiplier'
|
|
31
37
|
,FILL char(1) label='Fill character'
|
|
32
38
|
,NOEDIT num length=3 label='Is picture string noedit?'
|
|
33
|
-
,TYPE char(1) label='Type of format'
|
|
34
39
|
,SEXCL char(1) label='Start exclusion'
|
|
35
40
|
,EEXCL char(1) label='End exclusion'
|
|
36
41
|
,HLO char(13) label='Additional information'
|
package/package.json
CHANGED