@sasjs/core 4.46.0 → 4.46.2
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/base/mp_aligndecimal.sas +2 -1
- package/base/mp_cntlout.sas +12 -4
- package/base/mp_ds2md.sas +1 -0
- package/base/mp_loadformat.sas +36 -32
- package/base/mp_storediffs.sas +3 -3
- package/ddl/mddl_sas_cntlout.sas +25 -16
- package/package.json +1 -1
package/base/mp_aligndecimal.sas
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
aligndp4e49996=right(aligndp4e49996);
|
|
37
37
|
myvar=aligndp4e49996;
|
|
38
38
|
end;
|
|
39
|
+
drop aligndp4e49996;
|
|
39
40
|
|
|
40
41
|
Results (myvar variable):
|
|
41
42
|
|
|
@@ -61,7 +62,7 @@
|
|
|
61
62
|
7998580.8415
|
|
62
63
|
|
|
63
64
|
|
|
64
|
-
@param var The (data step) variable to
|
|
65
|
+
@param var The (data step, character) variable to modify
|
|
65
66
|
@param width= (8) The number of characters BEFORE the decimal point
|
|
66
67
|
|
|
67
68
|
<h4> SAS Macros </h4>
|
package/base/mp_cntlout.sas
CHANGED
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
<h4> SAS Macros </h4>
|
|
26
26
|
@li mddl_sas_cntlout.sas
|
|
27
27
|
@li mf_getuniquename.sas
|
|
28
|
+
@li mp_aligndecimal.sas
|
|
28
29
|
|
|
29
30
|
<h4> Related Macros </h4>
|
|
30
31
|
@li mf_getvarformat.sas
|
|
31
|
-
@li mp_aligndecimal.sas
|
|
32
32
|
@li mp_getformats.sas
|
|
33
33
|
@li mp_loadformat.sas
|
|
34
34
|
@li mp_ds2fmtds.sas
|
|
@@ -67,16 +67,24 @@ proc format lib=&libcat cntlout=&cntlds;
|
|
|
67
67
|
%end;
|
|
68
68
|
run;
|
|
69
69
|
|
|
70
|
-
data &cntlout;
|
|
70
|
+
data &cntlout/nonote2err;
|
|
71
71
|
if 0 then set &ddlds;
|
|
72
72
|
set &cntlds;
|
|
73
|
-
|
|
73
|
+
by type fmtname notsorted;
|
|
74
|
+
|
|
75
|
+
/* align the numeric values to avoid overlapping ranges */
|
|
76
|
+
if type in ("I","N") then do;
|
|
74
77
|
%mp_aligndecimal(start,width=16)
|
|
75
78
|
%mp_aligndecimal(end,width=16)
|
|
76
79
|
end;
|
|
80
|
+
|
|
81
|
+
/* create row marker. Data cannot be sorted without it! */
|
|
82
|
+
if first.fmtname then fmtrow=0;
|
|
83
|
+
fmtrow+1;
|
|
84
|
+
|
|
77
85
|
run;
|
|
78
86
|
proc sort;
|
|
79
|
-
by type fmtname
|
|
87
|
+
by type fmtname fmtrow;
|
|
80
88
|
run;
|
|
81
89
|
|
|
82
90
|
proc sql;
|
package/base/mp_ds2md.sas
CHANGED
package/base/mp_loadformat.sas
CHANGED
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages and preserve outputs
|
|
35
35
|
|
|
36
36
|
<h4> SAS Macros </h4>
|
|
37
|
-
@li mddl_sas_cntlout.sas
|
|
38
37
|
@li mf_getuniquename.sas
|
|
39
38
|
@li mf_nobs.sas
|
|
40
39
|
@li mp_abort.sas
|
|
40
|
+
@li mp_aligndecimal.sas
|
|
41
41
|
@li mp_cntlout.sas
|
|
42
42
|
@li mp_lockanytable.sas
|
|
43
43
|
@li mp_storediffs.sas
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
<h4> Related Macros </h4>
|
|
46
46
|
@li mddl_dc_difftable.sas
|
|
47
47
|
@li mddl_dc_locktable.sas
|
|
48
|
-
@li
|
|
49
|
-
@li mp_loadformat.test.sas
|
|
48
|
+
@li mp_loadformat.test.1.sas
|
|
49
|
+
@li mp_loadformat.test.2.sas
|
|
50
50
|
@li mp_lockanytable.sas
|
|
51
51
|
@li mp_stackdiffs.sas
|
|
52
52
|
|
|
@@ -79,13 +79,6 @@
|
|
|
79
79
|
%let &var=%upcase(&prefix._&var);
|
|
80
80
|
%end;
|
|
81
81
|
|
|
82
|
-
/*
|
|
83
|
-
format values can be up to 32767 wide. SQL joins on such a wide column can
|
|
84
|
-
cause buffer issues. Update ibufsize and reset at the end.
|
|
85
|
-
*/
|
|
86
|
-
%let ibufsize=%sysfunc(getoption(ibufsize));
|
|
87
|
-
options ibufsize=32767 ;
|
|
88
|
-
|
|
89
82
|
/* in DC, format catalogs maybe specified in the libds with a -FC extension */
|
|
90
83
|
%let libcat=%scan(&libcat,1,-);
|
|
91
84
|
|
|
@@ -148,16 +141,24 @@ select distinct
|
|
|
148
141
|
|
|
149
142
|
%mp_cntlout(libcat=&libcat,fmtlist=&fmtlist,cntlout=&base_fmts)
|
|
150
143
|
|
|
144
|
+
/* get a hash of the row */
|
|
145
|
+
%local cvars nvars;
|
|
146
|
+
%let cvars=TYPE FMTNAME START END LABEL PREFIX FILL SEXCL EEXCL HLO DECSEP
|
|
147
|
+
DIG3SEP DATATYPE LANGUAGE;
|
|
148
|
+
%let nvars=FMTROW MIN MAX DEFAULT LENGTH FUZZ MULT NOEDIT;
|
|
149
|
+
data &base_fmts/note2err;
|
|
150
|
+
set &base_fmts;
|
|
151
|
+
fmthash=%mp_md5(cvars=&cvars, nvars=&nvars);
|
|
152
|
+
run;
|
|
151
153
|
|
|
152
154
|
/**
|
|
153
155
|
* Ensure input table and base_formats have consistent lengths and types
|
|
154
156
|
*/
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if 0 then set &template;
|
|
159
|
-
length start end $10000;
|
|
157
|
+
data &inlibds/nonote2err;
|
|
158
|
+
length &delete_col $3 FMTROW 8 start end label $32767;
|
|
159
|
+
if 0 then set &base_fmts;
|
|
160
160
|
set &libds;
|
|
161
|
+
by type fmtname notsorted;
|
|
161
162
|
if &delete_col='' then &delete_col='No';
|
|
162
163
|
fmtname=upcase(fmtname);
|
|
163
164
|
type=upcase(type);
|
|
@@ -175,6 +176,14 @@ data &inlibds;
|
|
|
175
176
|
%mp_aligndecimal(start,width=16)
|
|
176
177
|
%mp_aligndecimal(end,width=16)
|
|
177
178
|
end;
|
|
179
|
+
|
|
180
|
+
/* update row marker - retain new var as fmtrow may already be in libds */
|
|
181
|
+
if first.fmtname then row=1;
|
|
182
|
+
else row+1;
|
|
183
|
+
drop row;
|
|
184
|
+
fmtrow=row;
|
|
185
|
+
|
|
186
|
+
fmthash=%mp_md5(cvars=&cvars, nvars=&nvars);
|
|
178
187
|
run;
|
|
179
188
|
|
|
180
189
|
/**
|
|
@@ -185,12 +194,10 @@ create table &outds_add(drop=&delete_col) as
|
|
|
185
194
|
select a.*
|
|
186
195
|
from &inlibds a
|
|
187
196
|
left join &base_fmts b
|
|
188
|
-
on a.fmtname=b.fmtname
|
|
189
|
-
and a.start=b.start
|
|
190
|
-
and a.type=b.type
|
|
197
|
+
on a.type=b.type and a.fmtname=b.fmtname and a.fmtrow=b.fmtrow
|
|
191
198
|
where b.fmtname is null
|
|
192
199
|
and upcase(a.&delete_col) ne "YES"
|
|
193
|
-
order by type, fmtname,
|
|
200
|
+
order by type, fmtname, fmtrow;
|
|
194
201
|
|
|
195
202
|
/**
|
|
196
203
|
* Identify deleted records
|
|
@@ -199,11 +206,9 @@ create table &outds_del(drop=&delete_col) as
|
|
|
199
206
|
select a.*
|
|
200
207
|
from &inlibds a
|
|
201
208
|
inner join &base_fmts b
|
|
202
|
-
on a.fmtname=b.fmtname
|
|
203
|
-
and a.start=b.start
|
|
204
|
-
and a.type=b.type
|
|
209
|
+
on a.type=b.type and a.fmtname=b.fmtname and a.fmtrow=b.fmtrow
|
|
205
210
|
where upcase(a.&delete_col)="YES"
|
|
206
|
-
order by type, fmtname,
|
|
211
|
+
order by type, fmtname, fmtrow;
|
|
207
212
|
|
|
208
213
|
/**
|
|
209
214
|
* Identify modified records
|
|
@@ -212,13 +217,10 @@ create table &outds_mod (drop=&delete_col) as
|
|
|
212
217
|
select a.*
|
|
213
218
|
from &inlibds a
|
|
214
219
|
inner join &base_fmts b
|
|
215
|
-
on a.fmtname=b.fmtname
|
|
216
|
-
and a.start=b.start
|
|
217
|
-
and a.type=b.type
|
|
220
|
+
on a.type=b.type and a.fmtname=b.fmtname and a.fmtrow=b.fmtrow
|
|
218
221
|
where upcase(a.&delete_col) ne "YES"
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
options ibufsize=&ibufsize;
|
|
222
|
+
and a.fmthash ne b.fmthash
|
|
223
|
+
order by type, fmtname, fmtrow;
|
|
222
224
|
|
|
223
225
|
%mp_abort(
|
|
224
226
|
iftrue=(&syscc ne 0)
|
|
@@ -227,19 +229,21 @@ options ibufsize=&ibufsize;
|
|
|
227
229
|
)
|
|
228
230
|
|
|
229
231
|
%if &loadtarget=YES %then %do;
|
|
232
|
+
/* new records plus base records that are not deleted or modified */
|
|
230
233
|
data &ds1;
|
|
231
234
|
merge &base_fmts(in=base)
|
|
232
235
|
&outds_mod(in=mod)
|
|
233
236
|
&outds_add(in=add)
|
|
234
237
|
&outds_del(in=del);
|
|
235
238
|
if not del and not mod;
|
|
236
|
-
by type fmtname
|
|
239
|
+
by type fmtname fmtrow;
|
|
237
240
|
run;
|
|
241
|
+
/* add back the modified records */
|
|
238
242
|
data &stagedata;
|
|
239
243
|
set &ds1 &outds_mod;
|
|
240
244
|
run;
|
|
241
245
|
proc sort;
|
|
242
|
-
by type fmtname
|
|
246
|
+
by type fmtname fmtrow;
|
|
243
247
|
run;
|
|
244
248
|
%end;
|
|
245
249
|
/* mp abort needs to run outside of conditional blocks */
|
|
@@ -287,7 +291,7 @@ options ibufsize=&ibufsize;
|
|
|
287
291
|
|
|
288
292
|
%mp_storediffs(&libcat-FC
|
|
289
293
|
,&base_fmts
|
|
290
|
-
,TYPE FMTNAME
|
|
294
|
+
,TYPE FMTNAME FMTROW
|
|
291
295
|
,delds=&outds_del
|
|
292
296
|
,modds=&outds_mod
|
|
293
297
|
,appds=&outds_add
|
package/base/mp_storediffs.sas
CHANGED
|
@@ -147,9 +147,9 @@ run;
|
|
|
147
147
|
|
|
148
148
|
%if %index(&libds,-)>0 and %scan(&libds,2,-)=FC %then %do;
|
|
149
149
|
/* this is a format catalog - cannot query cols directly */
|
|
150
|
-
%let vlist="FMTNAME","START","END","LABEL","MIN","MAX"
|
|
151
|
-
,"FUZZ","PREFIX","MULT","FILL","NOEDIT","
|
|
152
|
-
,"DECSEP","DIG3SEP","DATATYPE","LANGUAGE";
|
|
150
|
+
%let vlist="TYPE","FMTNAME","FMTROW","START","END","LABEL","MIN","MAX"
|
|
151
|
+
,"DEFAULT","LENGTH","FUZZ","PREFIX","MULT","FILL","NOEDIT","SEXCL"
|
|
152
|
+
,"EEXCL","HLO","DECSEP","DIG3SEP","DATATYPE","LANGUAGE";
|
|
153
153
|
%end;
|
|
154
154
|
%else %let vlist=%mf_getvarlist(&libds,dlm=%str(,),quote=DOUBLE);
|
|
155
155
|
|
package/ddl/mddl_sas_cntlout.sas
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
@file
|
|
3
3
|
@brief The CNTLOUT table generated by proc format
|
|
4
|
-
@details
|
|
5
|
-
therefore the max possible lengths
|
|
6
|
-
|
|
4
|
+
@details The actual CNTLOUT table may have varying variable lengths,
|
|
5
|
+
depending on the data values, therefore the max possible lengths
|
|
6
|
+
(given various practical restrictions) are described here to enable
|
|
7
|
+
consistency when dealing with format data.
|
|
7
8
|
|
|
8
9
|
**/
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
%macro mddl_sas_cntlout(libds=WORK.CNTLOUT);
|
|
12
13
|
|
|
13
|
-
proc sql;
|
|
14
|
-
create table &libds(
|
|
15
|
-
TYPE char(1)
|
|
16
|
-
,FMTNAME char(32)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
SQL dependency removed (proc sql needs to accommodate 3 index values in
|
|
20
|
-
a 32767 ibufsize limit)
|
|
21
|
-
*/
|
|
22
|
-
,START char(10000) label='Starting value for format'
|
|
14
|
+
proc sql;
|
|
15
|
+
create table &libds(
|
|
16
|
+
TYPE char(1) label='Type of format - either N (num fmt), C (char fmt), I (num infmt) or J (char infmt)'
|
|
17
|
+
,FMTNAME char(32) label='Format name'
|
|
18
|
+
,FMTROW num label='CALCULATED Position of record by FMTNAME (reqd for multilabel formats)'
|
|
19
|
+
,START char(32767) label='Starting value for format'
|
|
23
20
|
/*
|
|
24
21
|
Keep lengths of START and END the same to avoid this err:
|
|
25
22
|
"Start is greater than end: -<."
|
|
26
23
|
Similar usage note: https://support.sas.com/kb/69/330.html
|
|
27
24
|
*/
|
|
28
|
-
,END char(
|
|
25
|
+
,END char(32767) label='Ending value for format'
|
|
29
26
|
,LABEL char(32767) label='Format value label'
|
|
30
27
|
,MIN num length=3 label='Minimum length'
|
|
31
28
|
,MAX num length=3 label='Maximum length'
|
|
@@ -38,11 +35,23 @@ create table &libds(
|
|
|
38
35
|
,NOEDIT num length=3 label='Is picture string noedit?'
|
|
39
36
|
,SEXCL char(1) label='Start exclusion'
|
|
40
37
|
,EEXCL char(1) label='End exclusion'
|
|
41
|
-
,HLO char(13) label='Additional information'
|
|
38
|
+
,HLO char(13) label='Additional information. M=MultiLabel'
|
|
42
39
|
,DECSEP char(1) label='Decimal separator'
|
|
43
40
|
,DIG3SEP char(1) label='Three-digit separator'
|
|
44
41
|
,DATATYPE char(8) label='Date/time/datetime?'
|
|
45
42
|
,LANGUAGE char(8) label='Language for date strings'
|
|
46
|
-
);
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
%local lib;
|
|
46
|
+
%let libds=%upcase(&libds);
|
|
47
|
+
%if %index(&libds,.)=0 %then %let lib=WORK;
|
|
48
|
+
%else %let lib=%scan(&libds,1,.);
|
|
49
|
+
|
|
50
|
+
proc datasets lib=&lib noprint;
|
|
51
|
+
modify %scan(&libds,-1,.);
|
|
52
|
+
index create
|
|
53
|
+
pk_cntlout=(type fmtname fmtrow)
|
|
54
|
+
/nomiss unique;
|
|
55
|
+
quit;
|
|
47
56
|
|
|
48
57
|
%mend mddl_sas_cntlout;
|
package/package.json
CHANGED