@sasjs/core 4.68.3 → 5.1.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/README.md +22 -11
- package/base/mf_getuniquelibref.sas +2 -4
- package/base/mp_abort.sas +1 -1
- package/base/mp_ds2csv.sas +2 -2
- package/base/mp_ds2ddl.sas +388 -24
- package/base/mp_dsmeta.sas +1 -1
- package/base/mp_filterstore.sas +3 -3
- package/base/mp_getmaxvarlengths.sas +1 -1
- package/base/mp_lib2inserts.sas +1 -1
- package/base/mp_retainedkey.sas +4 -4
- package/base/mp_stackdiffs.sas +3 -3
- package/base/mp_storediffs.sas +1 -1
- package/fcmp/mcf_getfmttype.sas +3 -6
- package/fcmp/mcf_length.sas +3 -6
- package/fcmp/mcf_string2file.sas +3 -6
- package/package.json +10 -4
- package/server/ms_testservice.sas +1 -1
- package/xplatform/mx_createfile.sas +127 -0
- package/xplatform/{mx_testservice.sas → mx_execute.sas} +3 -3
- package/base/mp_coretable.sas +0 -73
- package/base/mp_getddl.sas +0 -405
- package/base/mp_testservice.sas +0 -39
package/README.md
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[](http://npmjs.org/package/@sasjs/core)
|
|
4
4
|
[](https://github.com/sasjs/core/blob/main/.github/workflows/main.yml)
|
|
5
|
+
[](https://github.com/sasjs/core/blob/main/LICENSE)
|
|
6
|
+
[](https://npms.io/search?q=%40sasjs%2Fcore)
|
|
5
7
|

|
|
6
|
-
](https://github.com/sasjs/core/issues?q=is%3Aissue+is%3Aclosed)
|
|
8
|
+

|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
Much quality. Many standards. The **Macro Core** library exists to save time and development effort! Herein ye shall find a veritable host of MIT-licenced, production quality SAS macros. These are a mix of tools, utilities, functions and code generators that are useful in the context of [Application Development](https://sasapps.io) on the SAS platform (eg https://datacontroller.io). [Contributions](https://github.com/sasjs/core/blob/main/.github/CONTRIBUTING.md) are welcome.
|
|
@@ -129,6 +130,16 @@ filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
|
|
129
130
|
%inc mc;
|
|
130
131
|
```
|
|
131
132
|
|
|
133
|
+
## Agent Skills
|
|
134
|
+
|
|
135
|
+
This repo ships with agent skills (in `.agents/skills`) to help coding assistants write idiomatic SAS and follow the @sasjs/core standards. The canonical versions live in the [sasjs/skills](https://github.com/sasjs/skills) repo and cover SAS language, @sasjs/core, @sasjs/adapter, @sasjs/cli, the SASjs framework, and @sasjs/server.
|
|
136
|
+
|
|
137
|
+
To install or update them in your own project, run:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npx skills add sasjs/skills
|
|
141
|
+
```
|
|
142
|
+
|
|
132
143
|
## Standards
|
|
133
144
|
|
|
134
145
|
### File Properties
|
|
@@ -193,7 +204,7 @@ When contributing to this library, it is therefore important to ensure that all
|
|
|
193
204
|
- no trailing white space
|
|
194
205
|
- no invisible characters, other than spaces. If invisibles are needed, use hex literals.
|
|
195
206
|
- Macro variables should not have the trailing dot (`&var` not `&var.`) unless necessary to prevent incorrect resolution
|
|
196
|
-
- The closing `%mend
|
|
207
|
+
- The closing `%mend` statement **must** contain the macro name, eg `%mend mymacro;` (enforced by the `hasMacroNameInMend` lint rule).
|
|
197
208
|
- All macros should be defined with brackets, even if no variables are needed - ie `%macro x();` not `%macro x;`
|
|
198
209
|
- Mandatory parameters should be positional, all optional parameters should be keyword (var=) style.
|
|
199
210
|
- All dataset references must be 2 level (eg `work.blah`, not `blah`). This is to avoid contention when options [DATASTMTCHK](https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000279064.htm)=ALLKEYWORDS is in effect, or the [USER](https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/n18m1vkqmeo4esn1moikt23zhp8s.htm) library is active.
|
|
@@ -209,15 +220,15 @@ When contributing to this library, it is therefore important to ensure that all
|
|
|
209
220
|
|
|
210
221
|
## Breaking Changes
|
|
211
222
|
|
|
212
|
-
We are currently on major release
|
|
223
|
+
We are currently on major release v5. The following breaking changes were applied as part of the v5 release:
|
|
213
224
|
|
|
214
|
-
* mcf_xxx macros
|
|
215
|
-
* mcf_xxx macros
|
|
216
|
-
* mf_getuniquelibref.sas
|
|
217
|
-
* mp_abort.sas
|
|
218
|
-
* mp_coretable.sas
|
|
219
|
-
* mp_getddl.sas
|
|
220
|
-
* mp_testservice.sas
|
|
225
|
+
* mcf_xxx macros - the `insert_cmplib` option was removed (the option is now checked automatically with value inserted only if needed)
|
|
226
|
+
* mcf_xxx macros - the `wrap=` option now defaults to YES for convenience. Set this option explicitly to avoid issues.
|
|
227
|
+
* mf_getuniquelibref.sas - the deprecated maxtries parameter was removed (no longer needed)
|
|
228
|
+
* mp_abort.sas - the redundant type= parameter was removed.
|
|
229
|
+
* mp_coretable.sas - removed, and replaced by the standalone macros in the `ddl` folder
|
|
230
|
+
* mp_getddl.sas - renamed to mp_ds2ddl.sas (consistent with other ds2xxx macros). The default for SHOWLOG is now YES instead of NO.
|
|
231
|
+
* mp_testservice.sas - renamed to mx_execute.sas (as it doesn't actually test anything, and the mp_ suite should not reference mx_ macros)
|
|
221
232
|
|
|
222
233
|
## Star Gazing
|
|
223
234
|
|
|
@@ -19,15 +19,13 @@
|
|
|
19
19
|
@param [in] prefix= (mclib) first part of the returned libref. As librefs can
|
|
20
20
|
be as long as 8 characters, a maximum length of 7 characters is premitted
|
|
21
21
|
for this prefix.
|
|
22
|
-
@param [in] maxtries= (1000) Deprecated parameter. Remains here to ensure a
|
|
23
|
-
non-breaking change. Will be removed in v5.
|
|
24
22
|
|
|
25
23
|
@version 9.2
|
|
26
24
|
@author Allan Bowe
|
|
27
25
|
**/
|
|
28
26
|
|
|
29
|
-
%macro mf_getuniquelibref(prefix=mc
|
|
30
|
-
%local x;
|
|
27
|
+
%macro mf_getuniquelibref(prefix=mc);
|
|
28
|
+
%local x maxtries;
|
|
31
29
|
|
|
32
30
|
%if ( %length(&prefix) gt 7 ) %then %do;
|
|
33
31
|
%put %str(ERR)OR: The prefix parameter cannot exceed 7 characters.;
|
package/base/mp_abort.sas
CHANGED
package/base/mp_ds2csv.sas
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
@li LABEL - Use the variable label (or name, if blank)
|
|
42
42
|
@li NAME - Use the variable name
|
|
43
43
|
@li SASJS - Used to create sasjs-formatted input CSVs, eg for use in
|
|
44
|
-
|
|
44
|
+
mx_execute.sas. This format will supply an input statement in the
|
|
45
45
|
first row, making ingestion by datastep a breeze. Special misisng values
|
|
46
46
|
will be prefixed with a period (eg `.A`) to enable ingestion on both SAS 9
|
|
47
47
|
and Viya. Dates / Datetimes etc are identified by the format type (lookup
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
%if &headerformat=SASJS %then %do;
|
|
94
94
|
%let delim=",";
|
|
95
95
|
%let termstr=CRLF;
|
|
96
|
-
%mcf_getfmttype(
|
|
96
|
+
%mcf_getfmttype()
|
|
97
97
|
%end;
|
|
98
98
|
%else %if &dlm=COMMA %then %let delim=",";
|
|
99
99
|
%else %let delim=";";
|
package/base/mp_ds2ddl.sas
CHANGED
|
@@ -1,42 +1,406 @@
|
|
|
1
1
|
/**
|
|
2
|
-
@file
|
|
3
|
-
@brief
|
|
4
|
-
@details
|
|
2
|
+
@file mp_ds2ddl.sas
|
|
3
|
+
@brief Extract DDL in various formats, by table or library
|
|
4
|
+
@details Data Definition Language relates to a set of SQL instructions used
|
|
5
|
+
to create tables in SAS or a database. The macro can be used at table or
|
|
6
|
+
library level. The default behaviour is to create DDL in SAS format.
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
Note - views are not currently supported.
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
|
|
12
|
+
data test(index=(pk=(x y)/unique /nomiss));
|
|
13
|
+
x=1;
|
|
14
|
+
y='blah';
|
|
15
|
+
label x='blah';
|
|
16
|
+
run;
|
|
17
|
+
proc sql; describe table &syslast;
|
|
18
|
+
%mp_ds2ddl(work,test,flavour=tsql,showlog=YES)
|
|
19
|
+
|
|
20
|
+
<h4> SAS Macros </h4>
|
|
21
|
+
@li mf_existfileref.sas
|
|
22
|
+
@li mf_getvarcount.sas
|
|
23
|
+
@li mp_getconstraints.sas
|
|
24
|
+
|
|
25
|
+
@param [in] libref Libref of the library to create DDL for. Should already
|
|
26
|
+
be assigned.
|
|
27
|
+
@param [in] ds dataset to create ddl for (optional)
|
|
7
28
|
@param [in] fref= (getddl) the fileref to which to _append_ the DDL. If it
|
|
8
29
|
does not exist, it will be created.
|
|
9
30
|
@param [in] flavour= (SAS) The type of DDL to create. Options:
|
|
10
31
|
@li SAS
|
|
11
32
|
@li TSQL
|
|
33
|
+
@li PGSQL
|
|
12
34
|
|
|
13
|
-
@param [in]showlog= (
|
|
35
|
+
@param [in]showlog= (YES) Set to NO to prevent the DDL showing in the log
|
|
14
36
|
@param [in] schema= () Choose a preferred schema name (default is to use
|
|
15
37
|
actual schema, else libref)
|
|
16
|
-
@param [in] applydttm= (NO) For non SAS DDL, choose if columns are created
|
|
17
|
-
native datetime2 format or regular decimal type
|
|
18
|
-
|
|
19
|
-
<h4> SAS Macros </h4>
|
|
20
|
-
@li mp_getddl.sas
|
|
38
|
+
@param [in] applydttm= (NO) For non SAS DDL, choose if columns are created
|
|
39
|
+
with native datetime2 format or regular decimal type
|
|
21
40
|
|
|
41
|
+
@version 9.3
|
|
42
|
+
@author Allan Bowe
|
|
22
43
|
**/
|
|
23
44
|
|
|
24
|
-
%macro mp_ds2ddl(
|
|
45
|
+
%macro mp_ds2ddl(libref,ds,fref=getddl,flavour=SAS,showlog=YES,schema=
|
|
25
46
|
,applydttm=NO
|
|
26
47
|
)/*/STORE SOURCE*/;
|
|
27
48
|
|
|
28
|
-
|
|
29
|
-
%
|
|
30
|
-
|
|
31
|
-
%
|
|
32
|
-
|
|
33
|
-
%
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
49
|
+
/* check fileref is assigned */
|
|
50
|
+
%if %mf_existfileref(&fref)=0 %then %do;
|
|
51
|
+
filename &fref temp ;
|
|
52
|
+
%end;
|
|
53
|
+
|
|
54
|
+
%if %length(&libref)=0 %then %let libref=WORK;
|
|
55
|
+
%let flavour=%upcase(&flavour);
|
|
56
|
+
|
|
57
|
+
proc sql noprint;
|
|
58
|
+
create table _data_ as
|
|
59
|
+
select * from dictionary.tables
|
|
60
|
+
where upcase(libname)="%upcase(&libref)"
|
|
61
|
+
and memtype='DATA' /* views not currently supported */
|
|
62
|
+
%if %length(&ds)>0 %then %do;
|
|
63
|
+
and upcase(memname)="%upcase(&ds)"
|
|
64
|
+
%end;
|
|
65
|
+
;
|
|
66
|
+
%local tabinfo; %let tabinfo=&syslast;
|
|
67
|
+
|
|
68
|
+
create table _data_ as
|
|
69
|
+
select * from dictionary.columns
|
|
70
|
+
where upcase(libname)="%upcase(&libref)"
|
|
71
|
+
%if %length(&ds)>0 %then %do;
|
|
72
|
+
and upcase(memname)="%upcase(&ds)"
|
|
73
|
+
%end;
|
|
74
|
+
;
|
|
75
|
+
%local colinfo; %let colinfo=&syslast;
|
|
76
|
+
|
|
77
|
+
%local dsnlist;
|
|
78
|
+
select distinct upcase(memname) into: dsnlist
|
|
79
|
+
separated by ' '
|
|
80
|
+
from &syslast
|
|
81
|
+
;
|
|
82
|
+
|
|
83
|
+
create table _data_ as
|
|
84
|
+
select * from dictionary.indexes
|
|
85
|
+
where upcase(libname)="%upcase(&libref)"
|
|
86
|
+
%if %length(&ds)>0 %then %do;
|
|
87
|
+
and upcase(memname)="%upcase(&ds)"
|
|
88
|
+
%end;
|
|
89
|
+
order by idxusage, indxname, indxpos
|
|
90
|
+
;
|
|
91
|
+
%local idxinfo; %let idxinfo=&syslast;
|
|
92
|
+
|
|
93
|
+
/* Extract all Primary Key and Unique data constraints */
|
|
94
|
+
%mp_getconstraints(lib=%upcase(&libref),ds=%upcase(&ds),outds=_data_)
|
|
95
|
+
%local colconst; %let colconst=&syslast;
|
|
96
|
+
|
|
97
|
+
%local constraints_used;
|
|
98
|
+
%macro addConst();
|
|
99
|
+
data _null_;
|
|
100
|
+
length ctype $11 constraint_name_orig $256 constraints_used $5000;
|
|
101
|
+
set &colconst(
|
|
102
|
+
where=(table_name="&curds" and constraint_type in ('PRIMARY','UNIQUE'))
|
|
103
|
+
) end=last;
|
|
104
|
+
file &fref mod;
|
|
105
|
+
by constraint_type constraint_name;
|
|
106
|
+
retain constraints_used;
|
|
107
|
+
constraint_name_orig=constraint_name;
|
|
108
|
+
if upcase(strip(constraint_type)) = 'PRIMARY' then ctype='PRIMARY KEY';
|
|
109
|
+
else ctype=strip(constraint_type);
|
|
110
|
+
%if &flavour=TSQL %then %do;
|
|
111
|
+
column_name=catt('[',column_name,']');
|
|
112
|
+
constraint_name=catt('[',constraint_name,']');
|
|
113
|
+
%end;
|
|
114
|
+
%else %if &flavour=PGSQL %then %do;
|
|
115
|
+
column_name=catt('"',column_name,'"');
|
|
116
|
+
constraint_name=catt('"',constraint_name,'"');
|
|
117
|
+
%end;
|
|
118
|
+
if first.constraint_name then do;
|
|
119
|
+
constraints_used = catx(' ', constraints_used, constraint_name_orig);
|
|
120
|
+
put " ,CONSTRAINT " constraint_name ctype "(" ;
|
|
121
|
+
put ' ' column_name;
|
|
122
|
+
end;
|
|
123
|
+
else put ' ,' column_name;
|
|
124
|
+
if last.constraint_name then do;
|
|
125
|
+
put " )";
|
|
126
|
+
call symput('constraints_used',strip(constraints_used));
|
|
127
|
+
end;
|
|
128
|
+
run;
|
|
129
|
+
%put &=constraints_used;
|
|
130
|
+
%mend addConst;
|
|
131
|
+
|
|
132
|
+
data _null_;
|
|
133
|
+
file &fref mod;
|
|
134
|
+
put "/* DDL generated by &sysuserid on %sysfunc(datetime(),datetime19.) */";
|
|
135
|
+
run;
|
|
136
|
+
|
|
137
|
+
%local x curds;
|
|
138
|
+
%if &flavour=SAS %then %do;
|
|
139
|
+
%do x=1 %to %sysfunc(countw(&dsnlist));
|
|
140
|
+
%let curds=%scan(&dsnlist,&x);
|
|
141
|
+
data _null_;
|
|
142
|
+
file &fref mod;
|
|
143
|
+
put "/* SAS Flavour DDL for %upcase(&libref).&curds */";
|
|
144
|
+
put "proc sql;";
|
|
145
|
+
run;
|
|
146
|
+
data _null_;
|
|
147
|
+
file &fref mod;
|
|
148
|
+
length lab $1024 typ $20;
|
|
149
|
+
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
|
150
|
+
|
|
151
|
+
if _n_=1 then do;
|
|
152
|
+
if memtype='DATA' then do;
|
|
153
|
+
put "create table &libref..&curds(";
|
|
154
|
+
end;
|
|
155
|
+
else do;
|
|
156
|
+
/* just a placeholder - we filter out views at the top */
|
|
157
|
+
put "create view &libref..&curds(";
|
|
158
|
+
end;
|
|
159
|
+
put " "@@;
|
|
160
|
+
end;
|
|
161
|
+
else put " ,"@@;
|
|
162
|
+
if length(format)>1 then fmt=" format="!!cats(format);
|
|
163
|
+
if length(label)>1 then
|
|
164
|
+
lab=" label="!!cats("'",tranwrd(label,"'","''"),"'");
|
|
165
|
+
if notnull='yes' then notnul=' not null';
|
|
166
|
+
if type='char' then typ=cats('char(',length,')');
|
|
167
|
+
else if length ne 8 then typ='num length='!!cats(length);
|
|
168
|
+
else typ='num';
|
|
169
|
+
put name typ fmt notnul lab;
|
|
170
|
+
run;
|
|
171
|
+
|
|
172
|
+
/* Extra step for data constraints */
|
|
173
|
+
%addConst()
|
|
174
|
+
|
|
175
|
+
data _null_;
|
|
176
|
+
file &fref mod;
|
|
177
|
+
put ');';
|
|
178
|
+
run;
|
|
179
|
+
|
|
180
|
+
/* Create Unique Indexes, but only if they were not already defined within
|
|
181
|
+
the Constraints section. */
|
|
182
|
+
data _null_;
|
|
183
|
+
*length ds $128;
|
|
184
|
+
set &idxinfo(
|
|
185
|
+
where=(
|
|
186
|
+
memname="&curds"
|
|
187
|
+
and unique='yes'
|
|
188
|
+
and indxname not in (
|
|
189
|
+
%sysfunc(tranwrd("&constraints_used",%str( ),%str(",")))
|
|
190
|
+
)
|
|
191
|
+
)
|
|
192
|
+
);
|
|
193
|
+
file &fref mod;
|
|
194
|
+
by idxusage indxname;
|
|
195
|
+
/* ds=cats(libname,'.',memname); */
|
|
196
|
+
if first.indxname then do;
|
|
197
|
+
put 'CREATE UNIQUE INDEX ' indxname "ON &libref..&curds (" ;
|
|
198
|
+
put ' ' name ;
|
|
199
|
+
end;
|
|
200
|
+
else put ' ,' name ;
|
|
201
|
+
*else put ' ,' name ;
|
|
202
|
+
if last.indxname then do;
|
|
203
|
+
put ');';
|
|
204
|
+
end;
|
|
205
|
+
run;
|
|
206
|
+
|
|
207
|
+
/*
|
|
208
|
+
ods output IntegrityConstraints=ic;
|
|
209
|
+
proc contents data=testali out2=info;
|
|
210
|
+
run;
|
|
211
|
+
*/
|
|
212
|
+
%end;
|
|
213
|
+
%end;
|
|
214
|
+
%else %if &flavour=TSQL %then %do;
|
|
215
|
+
/* if schema does not exist, set to be same as libref */
|
|
216
|
+
%local schemaactual;
|
|
217
|
+
proc sql noprint;
|
|
218
|
+
select sysvalue into: schemaactual
|
|
219
|
+
from dictionary.libnames
|
|
220
|
+
where upcase(libname)="&libref" and engine='SQLSVR';
|
|
221
|
+
%let schema=%sysfunc(coalescec(&schemaactual,&schema,&libref));
|
|
222
|
+
|
|
223
|
+
%do x=1 %to %sysfunc(countw(&dsnlist));
|
|
224
|
+
%let curds=%scan(&dsnlist,&x);
|
|
225
|
+
data _null_;
|
|
226
|
+
file &fref mod;
|
|
227
|
+
put "/* TSQL Flavour DDL for &schema..&curds */";
|
|
228
|
+
data _null_;
|
|
229
|
+
file &fref mod;
|
|
230
|
+
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
|
231
|
+
if _n_=1 then do;
|
|
232
|
+
if memtype='DATA' then do;
|
|
233
|
+
put "create table [&schema].[&curds](";
|
|
234
|
+
end;
|
|
235
|
+
else do;
|
|
236
|
+
/* just a placeholder - we filter out views at the top */
|
|
237
|
+
put "create view [&schema].[&curds](";
|
|
238
|
+
end;
|
|
239
|
+
put " "@@;
|
|
240
|
+
end;
|
|
241
|
+
else put " ,"@@;
|
|
242
|
+
format=upcase(format);
|
|
243
|
+
if 1=0 then; /* dummy if */
|
|
244
|
+
%if &applydttm=YES %then %do;
|
|
245
|
+
else if format=:'DATETIME' then fmt='[datetime2](7) ';
|
|
246
|
+
%end;
|
|
247
|
+
else if type='num' then fmt='[decimal](18,2)';
|
|
248
|
+
else if length le 8000 then fmt='[varchar]('!!cats(length)!!')';
|
|
249
|
+
else fmt=cats('[varchar](max)');
|
|
250
|
+
if notnull='yes' then notnul=' NOT NULL';
|
|
251
|
+
put "[" name +(-1) "]" fmt notnul;
|
|
252
|
+
run;
|
|
253
|
+
|
|
254
|
+
/* Extra step for data constraints */
|
|
255
|
+
%addConst()
|
|
256
|
+
|
|
257
|
+
/* Create Unique Indexes, but only if they were not already defined within
|
|
258
|
+
the Constraints section. */
|
|
259
|
+
data _null_;
|
|
260
|
+
*length ds $128;
|
|
261
|
+
set &idxinfo(
|
|
262
|
+
where=(
|
|
263
|
+
memname="&curds"
|
|
264
|
+
and unique='yes'
|
|
265
|
+
and indxname not in (
|
|
266
|
+
%sysfunc(tranwrd("&constraints_used",%str( ),%str(",")))
|
|
267
|
+
)
|
|
268
|
+
)
|
|
269
|
+
);
|
|
270
|
+
file &fref mod;
|
|
271
|
+
by idxusage indxname;
|
|
272
|
+
*ds=cats(libname,'.',memname);
|
|
273
|
+
if first.indxname then do;
|
|
274
|
+
/* add nonclustered in case of multiple unique indexes */
|
|
275
|
+
put ' ,index [' indxname +(-1) '] UNIQUE NONCLUSTERED (';
|
|
276
|
+
put ' [' name +(-1) ']';
|
|
277
|
+
end;
|
|
278
|
+
else put ' ,[' name +(-1) ']';
|
|
279
|
+
if last.indxname then do;
|
|
280
|
+
put ' )';
|
|
281
|
+
end;
|
|
282
|
+
run;
|
|
283
|
+
|
|
284
|
+
data _null_;
|
|
285
|
+
file &fref mod;
|
|
286
|
+
put ')';
|
|
287
|
+
put 'GO';
|
|
288
|
+
run;
|
|
289
|
+
|
|
290
|
+
/* add extended properties for labels */
|
|
291
|
+
data _null_;
|
|
292
|
+
file &fref mod;
|
|
293
|
+
length nm $64 lab $1024;
|
|
294
|
+
set &colinfo (where=(upcase(memname)="&curds" and label ne '')) end=last;
|
|
295
|
+
nm=cats("N'",tranwrd(name,"'","''"),"'");
|
|
296
|
+
lab=cats("N'",tranwrd(label,"'","''"),"'");
|
|
297
|
+
put ' ';
|
|
298
|
+
put "EXEC sys.sp_addextendedproperty ";
|
|
299
|
+
put " @name=N'MS_Description',@value=" lab ;
|
|
300
|
+
put " ,@level0type=N'SCHEMA',@level0name=N'&schema' ";
|
|
301
|
+
put " ,@level1type=N'TABLE',@level1name=N'&curds'";
|
|
302
|
+
put " ,@level2type=N'COLUMN',@level2name=" nm ;
|
|
303
|
+
if last then put 'GO';
|
|
304
|
+
run;
|
|
305
|
+
%end;
|
|
306
|
+
%end;
|
|
307
|
+
%else %if &flavour=PGSQL %then %do;
|
|
308
|
+
/* if schema does not exist, set to be same as libref */
|
|
309
|
+
%local schemaactual;
|
|
310
|
+
proc sql noprint;
|
|
311
|
+
select sysvalue into: schemaactual
|
|
312
|
+
from dictionary.libnames
|
|
313
|
+
where upcase(libname)="&libref" and engine='POSTGRES';
|
|
314
|
+
%let schema=%sysfunc(coalescec(&schemaactual,&schema,&libref));
|
|
315
|
+
data _null_;
|
|
316
|
+
file &fref mod;
|
|
317
|
+
put "CREATE SCHEMA &schema;";
|
|
318
|
+
%do x=1 %to %sysfunc(countw(&dsnlist));
|
|
319
|
+
%let curds=%scan(&dsnlist,&x);
|
|
320
|
+
%local curdsvarcount;
|
|
321
|
+
%let curdsvarcount=%mf_getvarcount(&libref..&curds);
|
|
322
|
+
%if &curdsvarcount>1600 %then %do;
|
|
323
|
+
data _null_;
|
|
324
|
+
file &fref mod;
|
|
325
|
+
put "/* &libref..&curds contains &curdsvarcount vars */";
|
|
326
|
+
put "/* Postgres cannot create tables with over 1600 vars */";
|
|
327
|
+
put "/* No DDL will be generated for this table";
|
|
328
|
+
run;
|
|
329
|
+
%end;
|
|
330
|
+
%else %do;
|
|
331
|
+
data _null_;
|
|
332
|
+
file &fref mod;
|
|
333
|
+
put "/* Postgres Flavour DDL for &schema..&curds */";
|
|
334
|
+
data _null_;
|
|
335
|
+
file &fref mod;
|
|
336
|
+
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
|
337
|
+
length fmt $32;
|
|
338
|
+
if _n_=1 then do;
|
|
339
|
+
if memtype='DATA' then do;
|
|
340
|
+
put "CREATE TABLE &schema..&curds (";
|
|
341
|
+
end;
|
|
342
|
+
else do;
|
|
343
|
+
/* just a placeholder - we filter out views at the top */
|
|
344
|
+
put "CREATE VIEW &schema..&curds (";
|
|
345
|
+
end;
|
|
346
|
+
put " "@@;
|
|
347
|
+
end;
|
|
348
|
+
else put " ,"@@;
|
|
349
|
+
format=upcase(format);
|
|
350
|
+
if 1=0 then; /* dummy if */
|
|
351
|
+
%if &applydttm=YES %then %do;
|
|
352
|
+
else if format=:'DATETIME' then fmt=' TIMESTAMP ';
|
|
353
|
+
%end;
|
|
354
|
+
else if type='num' then fmt=' DOUBLE PRECISION';
|
|
355
|
+
else fmt='VARCHAR('!!cats(length)!!')';
|
|
356
|
+
if notnull='yes' then notnul=' NOT NULL';
|
|
357
|
+
/* quote column names in case they represent reserved words */
|
|
358
|
+
name2=quote(trim(name));
|
|
359
|
+
put name2 fmt notnul;
|
|
360
|
+
run;
|
|
361
|
+
|
|
362
|
+
/* Extra step for data constraints */
|
|
363
|
+
%addConst()
|
|
364
|
+
|
|
365
|
+
data _null_;
|
|
366
|
+
file &fref mod;
|
|
367
|
+
put ');';
|
|
368
|
+
run;
|
|
369
|
+
|
|
370
|
+
/* Create Unique Indexes, but only if they were not already defined within
|
|
371
|
+
the Constraints section. */
|
|
372
|
+
data _null_;
|
|
373
|
+
*length ds $128;
|
|
374
|
+
set &idxinfo(
|
|
375
|
+
where=(
|
|
376
|
+
memname="&curds"
|
|
377
|
+
and unique='yes'
|
|
378
|
+
and indxname not in (
|
|
379
|
+
%sysfunc(tranwrd("&constraints_used",%str( ),%str(",")))
|
|
380
|
+
)
|
|
381
|
+
)
|
|
382
|
+
);
|
|
383
|
+
file &fref mod;
|
|
384
|
+
by idxusage indxname;
|
|
385
|
+
if first.indxname then do;
|
|
386
|
+
put 'CREATE UNIQUE INDEX "' indxname +(-1) '" ' "ON &schema..&curds(";
|
|
387
|
+
put ' "' name +(-1) '"' ;
|
|
388
|
+
end;
|
|
389
|
+
else put ' ,"' name +(-1) '"';
|
|
390
|
+
if last.indxname then do;
|
|
391
|
+
put ');';
|
|
392
|
+
end;
|
|
393
|
+
run;
|
|
394
|
+
%end;
|
|
395
|
+
%end;
|
|
396
|
+
%end;
|
|
397
|
+
%if %upcase(&showlog)=YES %then %do;
|
|
398
|
+
options ps=max;
|
|
399
|
+
data _null_;
|
|
400
|
+
infile &fref;
|
|
401
|
+
input;
|
|
402
|
+
putlog _infile_;
|
|
403
|
+
run;
|
|
404
|
+
%end;
|
|
41
405
|
|
|
42
406
|
%mend mp_ds2ddl;
|
package/base/mp_dsmeta.sas
CHANGED
package/base/mp_filterstore.sas
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|AND|AND|1|SOME_TIME|=|77333|
|
|
24
24
|
@param [in] filter_summary= (PERM.FILTER_SUMMARY) Permanent table containing
|
|
25
25
|
summary filter values. The definition is available by running
|
|
26
|
-
|
|
26
|
+
mddl_dc_filtersummary.sas as follows: `%mddl_dc_filtersummary()`. Example
|
|
27
27
|
values:
|
|
28
28
|
|FILTER_RK:best.|FILTER_HASH:$32.|FILTER_TABLE:$41.|PROCESSED_DTTM:datetime19.|
|
|
29
29
|
|---|---|---|---|
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|`3 `|`8048BD908DBBD83D013560734E90D394 `|`VIYA6014.MPE_TABLES `|`1956093620.6`|
|
|
33
33
|
@param [in] filter_detail= (PERM.FILTER_DETAIL) Permanent table containing
|
|
34
34
|
detailed (raw) filter values. The definition is available by running
|
|
35
|
-
|
|
35
|
+
mddl_dc_filterdetail.sas as follows: `%mddl_dc_filterdetail()`. Example
|
|
36
36
|
values:
|
|
37
37
|
|FILTER_HASH:$32.|FILTER_LINE:best.|GROUP_LOGIC:$3.|SUBGROUP_LOGIC:$3.|SUBGROUP_ID:best.|VARIABLE_NM:$32.|OPERATOR_NM:$12.|RAW_VALUE:$4000.|PROCESSED_DTTM:datetime19.|
|
|
38
38
|
|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
|`87737DB9EEE2650F5C89956CEAD0A14F `|`1 `|`AND `|`AND `|`1 `|`PRIMARY_KEY_FIELD `|`IN `|`(1,2,3) `|`1956084451.9 `|
|
|
42
42
|
@param [in] lock_table= (PERM.LOCK_TABLE) Permanent locking table. Used to
|
|
43
43
|
manage concurrent access. The definition is available by running
|
|
44
|
-
|
|
44
|
+
mddl_dc_locktable.sas as follows: `%mddl_dc_locktable()`.
|
|
45
45
|
@param [in] maxkeytable= (0) Optional permanent reference table used for
|
|
46
46
|
retained key tracking. Described in mp_retainedkey.sas.
|
|
47
47
|
@param [in] mdebug= (1) set to 1 to enable DEBUG messages
|
package/base/mp_lib2inserts.sas
CHANGED
package/base/mp_retainedkey.sas
CHANGED
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
@li permlib.base_table - the target table to be loaded (**not** loaded by this
|
|
25
25
|
macro)
|
|
26
26
|
@li permlib.maxkeytable - optional, used to store load metaadata.
|
|
27
|
-
The definition is available
|
|
28
|
-
|
|
27
|
+
The definition is available in mddl_dc_maxkeytable.sas as follows:
|
|
28
|
+
`%mddl_dc_maxkeytable()`.
|
|
29
29
|
@li permlib.locktable - Necessary if maxkeytable is being populated. The
|
|
30
|
-
definition is available
|
|
31
|
-
|
|
30
|
+
definition is available in mddl_dc_locktable.sas as follows:
|
|
31
|
+
`%mddl_dc_locktable()`.
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
@param [in] base_lib= (WORK) Libref of the base (target) table.
|
package/base/mp_stackdiffs.sas
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
In both cases, it is necessary that the transactions are stored using
|
|
15
15
|
the mp_storediffs.sas macro, or at least that the underlying table is
|
|
16
|
-
structured as per the definition in
|
|
16
|
+
structured as per the definition in mddl_dc_difftable.sas
|
|
17
17
|
|
|
18
18
|
<b>This</b> macro is used to convert the stored changes (tall format) into
|
|
19
19
|
staged changes (wide format), with base table values incorporated (in the
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
in libref.dataset format.
|
|
167
167
|
@param [in] auditlibds Dataset with previously applied transactions, to be
|
|
168
168
|
re-applied. Use libref.dataset format.
|
|
169
|
-
DDL as follows: %
|
|
169
|
+
DDL as follows: %mddl_dc_difftable()
|
|
170
170
|
@param [in] key Space seperated list of key variables
|
|
171
171
|
@param [in] mdebug= Set to 1 to enable DEBUG messages and preserve outputs
|
|
172
172
|
@param [in] processed_dttm_var= (0) If a variable is being used to mark
|
|
@@ -194,7 +194,7 @@
|
|
|
194
194
|
@li mp_ds2squeeze.sas
|
|
195
195
|
|
|
196
196
|
<h4> Related Macros </h4>
|
|
197
|
-
@li
|
|
197
|
+
@li mddl_dc_difftable.sas
|
|
198
198
|
@li mp_stackdiffs.test.sas
|
|
199
199
|
@li mp_storediffs.sas
|
|
200
200
|
@li mp_stripdiffs.sas
|
package/base/mp_storediffs.sas
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
@param [in] appds= (0) Dataset with appended records
|
|
49
49
|
@param [in] modds= (0) Dataset with modified records
|
|
50
50
|
@param [out] outds= (work.mp_storediffs) Output table containing stored data.
|
|
51
|
-
DDL as follows: %
|
|
51
|
+
DDL as follows: %mddl_dc_difftable()
|
|
52
52
|
|
|
53
53
|
@param [in] processed_dttm= (0) Provide a datetime constant in relation to
|
|
54
54
|
the actual load time. If not provided, current timestamp is used.
|