@sasjs/core 4.7.0 → 4.8.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/base/mp_cntlout.sas +85 -0
- package/base/mp_getformats.sas +2 -2
- package/base/mp_loadformat.sas +29 -34
- package/base/mp_lockanytable.sas +1 -1
- package/base/mp_lockfilecheck.sas +7 -1
- package/base/mp_storediffs.sas +11 -2
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file mp_cntlout.sas
|
|
3
|
+
@brief Creates a cntlout dataset in a consistent format
|
|
4
|
+
@details The dataset produced by proc format in the cntlout option will vary
|
|
5
|
+
according to its contents.
|
|
6
|
+
|
|
7
|
+
When dealing with formats from an ETL perspective (eg in [Data Controller for
|
|
8
|
+
SAS](https://datacontroller.io)), it is important that the output dataset
|
|
9
|
+
has a consistent model (and compariable values).
|
|
10
|
+
|
|
11
|
+
This macro makes use of mddl_sas_cntlout.sas to provide the consistent model,
|
|
12
|
+
and will left-align the start and end values when dealing with numeric ranges
|
|
13
|
+
to enable consistency when checking for differences.
|
|
14
|
+
|
|
15
|
+
usage:
|
|
16
|
+
|
|
17
|
+
%mp_cntlout(libcat=yourlib.cat,cntlout=work.formatexport)
|
|
18
|
+
|
|
19
|
+
@param [in] libcat The library.catalog reference
|
|
20
|
+
@param [in] fmtlist= (0) provide a space separated list of specific formats to
|
|
21
|
+
extract
|
|
22
|
+
@param [in] iftrue= (1=1) A condition under which the macro should be executed
|
|
23
|
+
@param [out] cntlout= (work.fmtextract) Libds reference for the output dataset
|
|
24
|
+
|
|
25
|
+
<h4> SAS Macros </h4>
|
|
26
|
+
@li mddl_sas_cntlout.sas
|
|
27
|
+
@li mf_getuniquename.sas
|
|
28
|
+
|
|
29
|
+
<h4> Related Macros </h4>
|
|
30
|
+
@li mf_getvarformat.sas
|
|
31
|
+
@li mp_getformats.sas
|
|
32
|
+
@li mp_loadformat.sas
|
|
33
|
+
@li mp_ds2fmtds.sas
|
|
34
|
+
|
|
35
|
+
@version 9.2
|
|
36
|
+
@author Allan Bowe
|
|
37
|
+
@cond
|
|
38
|
+
**/
|
|
39
|
+
|
|
40
|
+
%macro mp_cntlout(
|
|
41
|
+
iftrue=(1=1)
|
|
42
|
+
,libcat=
|
|
43
|
+
,cntlout=work.fmtextract
|
|
44
|
+
,fmtlist=0
|
|
45
|
+
)/*/STORE SOURCE*/;
|
|
46
|
+
%local ddlds cntlds i;
|
|
47
|
+
|
|
48
|
+
%if not(%eval(%unquote(&iftrue))) %then %return;
|
|
49
|
+
|
|
50
|
+
%let ddlds=%mf_getuniquename();
|
|
51
|
+
%let cntlds=%mf_getuniquename();
|
|
52
|
+
|
|
53
|
+
%mddl_sas_cntlout(libds=&ddlds)
|
|
54
|
+
|
|
55
|
+
%if %index(&libcat,-)>0 and %scan(&libcat,2,-)=FC %then %do;
|
|
56
|
+
%let libcat=%scan(&libcat,1,-);
|
|
57
|
+
%end;
|
|
58
|
+
|
|
59
|
+
proc format lib=&libcat cntlout=&cntlds;
|
|
60
|
+
%if "&fmtlist" ne "0" %then %do;
|
|
61
|
+
select
|
|
62
|
+
%do i=1 %to %sysfunc(countw(&fmtlist));
|
|
63
|
+
%scan(&fmtlist,&i,%str( ))
|
|
64
|
+
%end;
|
|
65
|
+
;
|
|
66
|
+
%end;
|
|
67
|
+
run;
|
|
68
|
+
|
|
69
|
+
data &cntlout;
|
|
70
|
+
if 0 then set &ddlds;
|
|
71
|
+
set &cntlds;
|
|
72
|
+
if type="N" then do;
|
|
73
|
+
start=cats(start);
|
|
74
|
+
end=cats(end);
|
|
75
|
+
end;
|
|
76
|
+
run;
|
|
77
|
+
proc sort;
|
|
78
|
+
by fmtname start;
|
|
79
|
+
run;
|
|
80
|
+
|
|
81
|
+
proc sql;
|
|
82
|
+
drop table &ddlds,&cntlds;
|
|
83
|
+
|
|
84
|
+
%mend mp_cntlout;
|
|
85
|
+
/** @endcond */
|
package/base/mp_getformats.sas
CHANGED
|
@@ -113,10 +113,10 @@ create table &outsummary as
|
|
|
113
113
|
select &&fmtname&i;
|
|
114
114
|
run;
|
|
115
115
|
data &tempds;
|
|
116
|
-
|
|
116
|
+
if 0 then set &outdetail;
|
|
117
117
|
set &tempds;
|
|
118
118
|
run;
|
|
119
|
-
proc append base=&outdetail data=&tempds;
|
|
119
|
+
proc append base=&outdetail data=&tempds ;
|
|
120
120
|
run;
|
|
121
121
|
%end;
|
|
122
122
|
%end;
|
package/base/mp_loadformat.sas
CHANGED
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
@li mf_getuniquename.sas
|
|
39
39
|
@li mf_nobs.sas
|
|
40
40
|
@li mp_abort.sas
|
|
41
|
+
@li mp_cntlout.sas
|
|
41
42
|
@li mp_lockanytable.sas
|
|
42
43
|
|
|
43
44
|
<h4> Related Macros </h4>
|
|
@@ -66,17 +67,26 @@
|
|
|
66
67
|
);
|
|
67
68
|
/* set up local macro variables and temporary tables (with a prefix) */
|
|
68
69
|
%local err msg prefix dslist i var fmtlist ibufsize;
|
|
69
|
-
%let dslist=
|
|
70
|
+
%let dslist=base_fmts template inlibds ds1 stagedata storediffs;
|
|
70
71
|
%if &outds_add=0 %then %let dslist=&dslist outds_add;
|
|
71
72
|
%if &outds_del=0 %then %let dslist=&dslist outds_del;
|
|
72
73
|
%if &outds_mod=0 %then %let dslist=&dslist outds_mod;
|
|
73
|
-
%let prefix=%substr(%mf_getuniquename(),1,
|
|
74
|
+
%let prefix=%substr(%mf_getuniquename(),1,21);
|
|
74
75
|
%do i=1 %to %sysfunc(countw(&dslist));
|
|
75
76
|
%let var=%scan(&dslist,&i);
|
|
76
77
|
%local &var;
|
|
77
78
|
%let &var=%upcase(&prefix._&var);
|
|
78
79
|
%end;
|
|
79
80
|
|
|
81
|
+
/*
|
|
82
|
+
format values can be up to 32767 wide. SQL joins on such a wide column can
|
|
83
|
+
cause buffer issues. Update ibufsize and reset at the end.
|
|
84
|
+
*/
|
|
85
|
+
%let ibufsize=%sysfunc(getoption(ibufsize));
|
|
86
|
+
options ibufsize=32767 ;
|
|
87
|
+
|
|
88
|
+
/* in DC, format catalogs maybe specified in the libds with a -FC extension */
|
|
89
|
+
%let libcat=%scan(&libcat,1,-);
|
|
80
90
|
|
|
81
91
|
/* perform input validations */
|
|
82
92
|
%let err=0;
|
|
@@ -125,17 +135,9 @@ run;
|
|
|
125
135
|
*/
|
|
126
136
|
proc sql noprint;
|
|
127
137
|
select distinct fmtname into: fmtlist separated by ' ' from &libds;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
%do i=1 %to %sysfunc(countw(&fmtlist));
|
|
132
|
-
%scan(&fmtlist,&i,%str( ))
|
|
133
|
-
%end;
|
|
134
|
-
;
|
|
135
|
-
run;
|
|
136
|
-
proc sort data=&base;
|
|
137
|
-
by fmtname start;
|
|
138
|
-
run;
|
|
138
|
+
|
|
139
|
+
%mp_cntlout(libcat=&libcat,fmtlist=&fmtlist,cntlout=&base_fmts)
|
|
140
|
+
|
|
139
141
|
|
|
140
142
|
/**
|
|
141
143
|
* Ensure input table and base_formats have consistent lengths and types
|
|
@@ -148,19 +150,12 @@ data &inlibds;
|
|
|
148
150
|
if substr(fmtname,1,1)='$' then type='C';
|
|
149
151
|
else type='N';
|
|
150
152
|
end;
|
|
151
|
-
if type='N' then
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
set &base;
|
|
153
|
+
if type='N' then do;
|
|
154
|
+
start=cats(start);
|
|
155
|
+
end=cats(end);
|
|
156
|
+
end;
|
|
156
157
|
run;
|
|
157
158
|
|
|
158
|
-
/*
|
|
159
|
-
format values can be up to 32767 wide. SQL joins on such a wide column can
|
|
160
|
-
cause buffer issues. Update ibufsize and reset at the end.
|
|
161
|
-
*/
|
|
162
|
-
%let ibufsize=%sysfunc(getoption(ibufsize));
|
|
163
|
-
options ibufsize=32767 ;
|
|
164
159
|
|
|
165
160
|
/**
|
|
166
161
|
* Identify new records
|
|
@@ -237,9 +232,9 @@ options ibufsize=&ibufsize;
|
|
|
237
232
|
%end;
|
|
238
233
|
%if &locklibds ne 0 %then %do;
|
|
239
234
|
/* prevent parallel updates */
|
|
240
|
-
%mp_lockanytable(LOCK
|
|
241
|
-
lib=%scan(&libcat,1,.)
|
|
242
|
-
,ds=%scan(&libcat,2,.)
|
|
235
|
+
%mp_lockanytable(LOCK
|
|
236
|
+
,lib=%scan(&libcat,1,.)
|
|
237
|
+
,ds=%scan(&libcat,2,.)-FC
|
|
243
238
|
,ref=MP_LOADFORMAT commencing format load
|
|
244
239
|
,ctl_ds=&locklibds
|
|
245
240
|
)
|
|
@@ -250,8 +245,8 @@ options ibufsize=&ibufsize;
|
|
|
250
245
|
%if &locklibds ne 0 %then %do;
|
|
251
246
|
/* unlock the table */
|
|
252
247
|
%mp_lockanytable(UNLOCK
|
|
253
|
-
lib=%scan(&libcat,1,.)
|
|
254
|
-
,ds=%scan(&libcat,2,.)
|
|
248
|
+
,lib=%scan(&libcat,1,.)
|
|
249
|
+
,ds=%scan(&libcat,2,.)-FC
|
|
255
250
|
,ref=MP_LOADFORMAT completed format load
|
|
256
251
|
,ctl_ds=&locklibds
|
|
257
252
|
)
|
|
@@ -259,16 +254,16 @@ options ibufsize=&ibufsize;
|
|
|
259
254
|
/* track the changes */
|
|
260
255
|
%if &auditlibds ne 0 %then %do;
|
|
261
256
|
%if &locklibds ne 0 %then %do;
|
|
262
|
-
%mp_lockanytable(LOCK
|
|
263
|
-
lib=%scan(&auditlibds,1,.)
|
|
257
|
+
%mp_lockanytable(LOCK
|
|
258
|
+
,lib=%scan(&auditlibds,1,.)
|
|
264
259
|
,ds=%scan(&auditlibds,2,.)
|
|
265
260
|
,ref=MP_LOADFORMAT commencing audit table load
|
|
266
261
|
,ctl_ds=&locklibds
|
|
267
262
|
)
|
|
268
263
|
%end;
|
|
269
264
|
|
|
270
|
-
%mp_storediffs(&libcat
|
|
271
|
-
,&
|
|
265
|
+
%mp_storediffs(&libcat-FC
|
|
266
|
+
,&inlibds
|
|
272
267
|
,FMTNAME START
|
|
273
268
|
,delds=&outds_del
|
|
274
269
|
,modds=&outds_mod
|
|
@@ -279,7 +274,7 @@ options ibufsize=&ibufsize;
|
|
|
279
274
|
|
|
280
275
|
%if &locklibds ne 0 %then %do;
|
|
281
276
|
%mp_lockanytable(UNLOCK
|
|
282
|
-
lib=%scan(&auditlibds,1,.)
|
|
277
|
+
,lib=%scan(&auditlibds,1,.)
|
|
283
278
|
,ds=%scan(&auditlibds,2,.)
|
|
284
279
|
,ref=MP_LOADFORMAT commencing audit table load
|
|
285
280
|
,ctl_ds=&locklibds
|
package/base/mp_lockanytable.sas
CHANGED
|
@@ -37,7 +37,7 @@ run;
|
|
|
37
37
|
,mac=checklock.sas
|
|
38
38
|
,msg=Aborting with syscc=&syscc on entry.
|
|
39
39
|
)
|
|
40
|
-
%mp_abort(iftrue= (&libds=0)
|
|
40
|
+
%mp_abort(iftrue= ("&libds"="0")
|
|
41
41
|
,mac=&sysmacroname
|
|
42
42
|
,msg=%str(libds not provided)
|
|
43
43
|
)
|
|
@@ -46,6 +46,12 @@ run;
|
|
|
46
46
|
%let lib=%upcase(%scan(&libds,1,.));
|
|
47
47
|
%let ds=%upcase(%scan(&libds,2,.));
|
|
48
48
|
|
|
49
|
+
/* in DC, format catalogs are passed with a -FC suffix. No saslock here! */
|
|
50
|
+
%if %scan(&libds,2,-)=FC %then %do;
|
|
51
|
+
%put &sysmacroname: Format Catalog detected, no lockfile applied to &libds;
|
|
52
|
+
%return;
|
|
53
|
+
%end;
|
|
54
|
+
|
|
49
55
|
/* do not proceed if no observations can be processed */
|
|
50
56
|
%let msg=options obs = 0. syserrortext=%superq(syserrortext);
|
|
51
57
|
%mp_abort(iftrue= (%sysfunc(getoption(OBS))=0)
|
package/base/mp_storediffs.sas
CHANGED
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
%else %let dbg=*;
|
|
91
91
|
|
|
92
92
|
/* set up unique and temporary vars */
|
|
93
|
-
%local ds1 ds2 ds3 ds4 hashkey inds_auto inds_keep dslist;
|
|
93
|
+
%local ds1 ds2 ds3 ds4 hashkey inds_auto inds_keep dslist vlist;
|
|
94
94
|
%let ds1=%upcase(work.%mf_getuniquename(prefix=mpsd_ds1));
|
|
95
95
|
%let ds2=%upcase(work.%mf_getuniquename(prefix=mpsd_ds2));
|
|
96
96
|
%let ds3=%upcase(work.%mf_getuniquename(prefix=mpsd_ds3));
|
|
@@ -144,12 +144,21 @@ proc transpose data=&ds1
|
|
|
144
144
|
by &inds_keep &hashkey;
|
|
145
145
|
var _character_;
|
|
146
146
|
run;
|
|
147
|
+
|
|
148
|
+
%if %index(&libds,-)>0 and %scan(&libds,2,-)=FC %then %do;
|
|
149
|
+
/* this is a format catalog - cannot query cols directly */
|
|
150
|
+
%let vlist="FMTNAME","START","END","LABEL","MIN","MAX","DEFAULT","LENGTH"
|
|
151
|
+
,"FUZZ","PREFIX","MULT","FILL","NOEDIT","TYPE","SEXCL","EEXCL","HLO"
|
|
152
|
+
,"DECSEP","DIG3SEP","DATATYPE","LANGUAGE";
|
|
153
|
+
%end;
|
|
154
|
+
%else %let vlist=%mf_getvarlist(&libds,dlm=%str(,),quote=DOUBLE);
|
|
155
|
+
|
|
147
156
|
data &ds4;
|
|
148
157
|
length &inds_keep $41 tgtvar_nm $32;
|
|
149
158
|
set &ds2 &ds3 indsname=&inds_auto;
|
|
150
159
|
|
|
151
160
|
tgtvar_nm=upcase(tgtvar_nm);
|
|
152
|
-
if tgtvar_nm in (%upcase(
|
|
161
|
+
if tgtvar_nm in (%upcase(&vlist));
|
|
153
162
|
|
|
154
163
|
if &inds_auto="&ds2" then tgtvar_type='N';
|
|
155
164
|
else if &inds_auto="&ds3" then tgtvar_type='C';
|
package/package.json
CHANGED