@sasjs/core 4.68.3 → 5.0.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 CHANGED
@@ -129,6 +129,16 @@ filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
129
129
  %inc mc;
130
130
  ```
131
131
 
132
+ ## Agent Skills
133
+
134
+ 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.
135
+
136
+ To install or update them in your own project, run:
137
+
138
+ ```bash
139
+ npx skills add sasjs/skills
140
+ ```
141
+
132
142
  ## Standards
133
143
 
134
144
  ### File Properties
@@ -193,7 +203,7 @@ When contributing to this library, it is therefore important to ensure that all
193
203
  - no trailing white space
194
204
  - no invisible characters, other than spaces. If invisibles are needed, use hex literals.
195
205
  - Macro variables should not have the trailing dot (`&var` not `&var.`) unless necessary to prevent incorrect resolution
196
- - The closing `%mend;` should **not** contain the macro name.
206
+ - The closing `%mend` statement **must** contain the macro name, eg `%mend mymacro;` (enforced by the `hasMacroNameInMend` lint rule).
197
207
  - All macros should be defined with brackets, even if no variables are needed - ie `%macro x();` not `%macro x;`
198
208
  - Mandatory parameters should be positional, all optional parameters should be keyword (var=) style.
199
209
  - 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 +219,15 @@ When contributing to this library, it is therefore important to ensure that all
209
219
 
210
220
  ## Breaking Changes
211
221
 
212
- We are currently on major release v4. Breaking changes should be marked with the [deprecated](https://www.doxygen.nl/manual/commands.html#cmddeprecated) doxygen tag. The following changes are planned when the next major/breaking release (v5) becomes necessary:
222
+ We are currently on major release v5. The following breaking changes were applied as part of the v5 release:
213
223
 
214
- * mcf_xxx macros to have `insert_cmplib` option deprecated (the option is now checked automatically with value inserted only if needed)
215
- * mcf_xxx macros to have `wrap=` option defaulted to YES for convenience. Set this option explicitly to avoid issues.
216
- * mf_getuniquelibref.sas to have the deprecated maxtries parameter removed (no longer needed)
217
- * mp_abort.sas will have the redundant type= parameter removed.
218
- * mp_coretable.sas will be replaced by the standalone macros in the `ddl` folder (which are already available)
219
- * mp_getddl.sas to be renamed to mp_ds2ddl.sas (consistent with other ds2xxx macros). A wrapper macro is already in place, and you are able to use this immediately. The default for SHOWLOG will also be YES instead of NO.
220
- * mp_testservice.sas to be renamed as mp_execute.sas (as it doesn't actually test anything)
224
+ * mcf_xxx macros - the `insert_cmplib` option was removed (the option is now checked automatically with value inserted only if needed)
225
+ * mcf_xxx macros - the `wrap=` option now defaults to YES for convenience. Set this option explicitly to avoid issues.
226
+ * mf_getuniquelibref.sas - the deprecated maxtries parameter was removed (no longer needed)
227
+ * mp_abort.sas - the redundant type= parameter was removed.
228
+ * mp_coretable.sas - removed, and replaced by the standalone macros in the `ddl` folder
229
+ * mp_getddl.sas - renamed to mp_ds2ddl.sas (consistent with other ds2xxx macros). The default for SHOWLOG is now YES instead of NO.
230
+ * mp_testservice.sas - renamed to mp_execute.sas (as it doesn't actually test anything)
221
231
 
222
232
  ## Star Gazing
223
233
 
@@ -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,maxtries=1000);
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
@@ -61,7 +61,7 @@
61
61
  @cond
62
62
  **/
63
63
 
64
- %macro mp_abort(mac=mp_abort.sas, type=, msg=, iftrue=%str(1=1)
64
+ %macro mp_abort(mac=mp_abort.sas, msg=, iftrue=%str(1=1)
65
65
  , errds=work.mp_abort_errds
66
66
  , mode=REGULAR
67
67
  )/*/STORE SOURCE*/;
@@ -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
- mp_testservice.sas. This format will supply an input statement in the
44
+ mp_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(wrap=YES)
96
+ %mcf_getfmttype()
97
97
  %end;
98
98
  %else %if &dlm=COMMA %then %let delim=",";
99
99
  %else %let delim=";";
@@ -1,42 +1,406 @@
1
1
  /**
2
- @file
3
- @brief Fetches DDL for a specific table
4
- @details Uses mp_getddl under the hood
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
- @param [in] libds library.dataset to create ddl for
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= (NO) Set to YES to show the DDL in the log
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 with
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(libds,fref=getddl,flavour=SAS,showlog=YES,schema=
45
+ %macro mp_ds2ddl(libref,ds,fref=getddl,flavour=SAS,showlog=YES,schema=
25
46
  ,applydttm=NO
26
47
  )/*/STORE SOURCE*/;
27
48
 
28
- %local libref;
29
- %let libds=%upcase(&libds);
30
- %let libref=%scan(&libds,1,.);
31
- %if &libref=&libds %then %let libds=WORK.&libds;
32
-
33
- %mp_getddl(%scan(&libds,1,.)
34
- ,%scan(&libds,2,.)
35
- ,fref=&fref
36
- ,flavour=SAS
37
- ,showlog=&showlog
38
- ,schema=&schema
39
- ,applydttm=&applydttm
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;
@@ -56,7 +56,7 @@
56
56
  @li mp_dsmeta.test.sas
57
57
  @li mp_getcols.sas
58
58
  @li mp_getdbml.sas
59
- @li mp_getddl.sas
59
+ @li mp_ds2ddl.sas
60
60
  @li mp_getformats.sas
61
61
  @li mp_getpk.sas
62
62
  @li mp_guesspk.sas
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  @file
3
- @brief To be deprecated. Will execute a SASjs web service on SAS 9 or Viya
4
- @details Use the mx_testservice.sas macro instead (documentation can be
5
- found there)
3
+ @brief Executes a SASjs web service on SAS 9 or Viya
4
+ @details Wraps the mx_testservice.sas macro (documentation can be found
5
+ there)
6
6
 
7
7
  <h4> SAS Macros </h4>
8
8
  @li mx_testservice.sas
@@ -12,7 +12,7 @@
12
12
 
13
13
  **/
14
14
 
15
- %macro mp_testservice(program,
15
+ %macro mp_execute(program,
16
16
  inputfiles=0,
17
17
  inputdatasets=0,
18
18
  inputparams=0,
@@ -36,4 +36,4 @@
36
36
  viyacontext=&viyacontext
37
37
  )
38
38
 
39
- %mend mp_testservice;
39
+ %mend mp_execute;
@@ -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
- mp_coretable.sas as follows: `mp_coretable(FILTER_SUMMARY)`. Example
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
- mp_coretable.sas as follows: `mp_coretable(FILTER_DETAIL)`. Example
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
- mp_coretable.sas as follows: `mp_coretable(LOCKTABLE)`.
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
@@ -68,7 +68,7 @@
68
68
 
69
69
  %if &num2char=NO %then %do;
70
70
  /* compile length function for numeric fields */
71
- %mcf_length(wrap=YES, insert_cmplib=YES)
71
+ %mcf_length()
72
72
  %end;
73
73
 
74
74
  %if &num2char=NO
@@ -5,7 +5,7 @@
5
5
  macro.
6
6
  Usage:
7
7
 
8
- %mp_getddl(sashelp, schema=work, fref=tempref)
8
+ %mp_ds2ddl(sashelp, schema=work, fref=tempref)
9
9
 
10
10
  %mp_lib2inserts(sashelp, schema=work, outref=tempref)
11
11
 
@@ -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 by running mp_coretable.sas as follows:
28
- `mp_coretable(MAXKEYTABLE)`.
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 by running mp_coretable.sas as follows:
31
- `mp_coretable(LOCKTABLE)`.
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.
@@ -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 mp_coretable.sas (DIFFTABLE entry)
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: %mp_coretable(DIFFTABLE)
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 mp_coretable.sas
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
@@ -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: %mp_coretable(DIFFTABLE)
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.
@@ -16,7 +16,7 @@
16
16
 
17
17
  Usage:
18
18
 
19
- %mcf_getfmttype(wrap=YES, insert_cmplib=YES)
19
+ %mcf_getfmttype()
20
20
 
21
21
  data _null_;
22
22
  fmt1=mcf_getfmttype('DATE9.');
@@ -30,13 +30,11 @@
30
30
  > fmt1=DATE fmt2=DATETIME
31
31
  > fmt3=TIME
32
32
 
33
- @param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
33
+ @param [out] wrap= (YES) Choose NO to omit the proc fcmp wrapper.
34
34
  @param [out] lib= (work) The output library in which to create the catalog.
35
35
  @param [out] cat= (sasjs) The output catalog in which to create the package.
36
36
  @param [out] pkg= (utils) The output package in which to create the function.
37
37
  Uses a 3 part format: libref.catalog.package
38
- @param [out] insert_cmplib= DEPRECATED - The CMPLIB option is checked and
39
- values inserted only if needed.
40
38
 
41
39
  <h4> SAS Macros </h4>
42
40
  @li mcf_init.sas
@@ -50,8 +48,7 @@
50
48
 
51
49
  **/
52
50
 
53
- %macro mcf_getfmttype(wrap=NO
54
- ,insert_cmplib=DEPRECATED
51
+ %macro mcf_getfmttype(wrap=YES
55
52
  ,lib=WORK
56
53
  ,cat=SASJS
57
54
  ,pkg=UTILS
@@ -13,7 +13,7 @@
13
13
 
14
14
  Usage:
15
15
 
16
- %mcf_length(wrap=YES, insert_cmplib=YES)
16
+ %mcf_length()
17
17
 
18
18
  data _null_;
19
19
  ina=1;
@@ -31,13 +31,11 @@
31
31
 
32
32
  > outa=3 outb=4 outc=5 outd=0
33
33
 
34
- @param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
34
+ @param [out] wrap= (YES) Choose NO to omit the proc fcmp wrapper.
35
35
  @param [out] lib= (work) The output library in which to create the catalog.
36
36
  @param [out] cat= (sasjs) The output catalog in which to create the package.
37
37
  @param [out] pkg= (utils) The output package in which to create the function.
38
38
  Uses a 3 part format: libref.catalog.package
39
- @param [out] insert_cmplib= DEPRECATED - The CMPLIB option is checked and
40
- values inserted only if needed.
41
39
 
42
40
  <h4> SAS Macros </h4>
43
41
  @li mcf_init.sas
@@ -48,8 +46,7 @@
48
46
 
49
47
  **/
50
48
 
51
- %macro mcf_length(wrap=NO
52
- ,insert_cmplib=DEPRECATED
49
+ %macro mcf_length(wrap=YES
53
50
  ,lib=WORK
54
51
  ,cat=SASJS
55
52
  ,pkg=UTILS
@@ -16,7 +16,7 @@
16
16
 
17
17
  Usage:
18
18
 
19
- %mcf_string2file(wrap=YES, insert_cmplib=YES)
19
+ %mcf_string2file()
20
20
 
21
21
  data _null_;
22
22
  rc=mcf_string2file(
@@ -31,13 +31,11 @@
31
31
  putlog _infile_;
32
32
  run;
33
33
 
34
- @param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
34
+ @param [out] wrap= (YES) Choose NO to omit the proc fcmp wrapper.
35
35
  @param [out] lib= (work) The output library in which to create the catalog.
36
36
  @param [out] cat= (sasjs) The output catalog in which to create the package.
37
37
  @param [out] pkg= (utils) The output package in which to create the function.
38
38
  Uses a 3 part format: libref.catalog.package
39
- @param [out] insert_cmplib= DEPRECATED - The CMPLIB option is checked and
40
- values inserted only if needed.
41
39
 
42
40
  <h4> SAS Macros </h4>
43
41
  @li mcf_init.sas
@@ -48,8 +46,7 @@
48
46
 
49
47
  **/
50
48
 
51
- %macro mcf_string2file(wrap=NO
52
- ,insert_cmplib=DEPRECATED
49
+ %macro mcf_string2file(wrap=YES
53
50
  ,lib=WORK
54
51
  ,cat=SASJS
55
52
  ,pkg=UTILS
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "maintainers": [
36
36
  "https://sasapps.io"
37
37
  ],
38
- "version": "4.68.3"
38
+ "version": "5.0.0"
39
39
  }
@@ -42,7 +42,7 @@
42
42
  @li ms_runstp.sas
43
43
 
44
44
  <h4> Related Programs </h4>
45
- @li mp_testservice.test.sas
45
+ @li mp_execute.sas
46
46
 
47
47
  @version 9.4
48
48
  @author Allan Bowe
@@ -1,73 +0,0 @@
1
- /**
2
- @file
3
- @brief Create the permanent Core tables
4
- @details Several macros in the [core](https://github.com/sasjs/core) library
5
- make use of permanent tables. To avoid duplication in definitions, this
6
- macro provides a central location for managing the corresponding DDL.
7
-
8
- Note - this macro is likely to be deprecated in future in favour of a
9
- dedicated "datamodel" folder (prefix mddl)
10
-
11
- Any corresponding data would go in a seperate repo, to avoid this one
12
- ballooning in size!
13
-
14
- Example usage:
15
-
16
- %mp_coretable(LOCKTABLE,libds=work.locktable)
17
-
18
- @param [in] table_ref The type of table to create. Example values:
19
- @li DIFFTABLE
20
- @li FILTER_DETAIL
21
- @li FILTER_SUMMARY
22
- @li LOCKANYTABLE
23
- @li MAXKEYTABLE
24
- @param [in] libds= (0) The library.dataset reference used to create the table.
25
- If not provided, then the DDL is simply printed to the log.
26
-
27
- <h4> SAS Macros </h4>
28
- @li mddl_dc_difftable.sas
29
- @li mddl_dc_filterdetail.sas
30
- @li mddl_dc_filtersummary.sas
31
- @li mddl_dc_locktable.sas
32
- @li mddl_dc_maxkeytable.sas
33
- @li mf_getuniquename.sas
34
-
35
- <h4> Related Macros </h4>
36
- @li mp_filterstore.sas
37
- @li mp_lockanytable.sas
38
- @li mp_retainedkey.sas
39
- @li mp_storediffs.sas
40
- @li mp_stackdiffs.sas
41
-
42
- @version 9.2
43
- @author Allan Bowe
44
-
45
- **/
46
-
47
- %macro mp_coretable(table_ref,libds=0
48
- )/*/STORE SOURCE*/;
49
- %local outds ;
50
- %let outds=%sysfunc(ifc(&libds=0,%mf_getuniquename(),&libds));
51
- proc sql;
52
- %if &table_ref=DIFFTABLE %then %do;
53
- %mddl_dc_difftable(libds=&outds)
54
- %end;
55
- %else %if &table_ref=LOCKTABLE %then %do;
56
- %mddl_dc_locktable(libds=&outds)
57
- %end;
58
- %else %if &table_ref=FILTER_SUMMARY %then %do;
59
- %mddl_dc_filtersummary(libds=&outds)
60
- %end;
61
- %else %if &table_ref=FILTER_DETAIL %then %do;
62
- %mddl_dc_filterdetail(libds=&outds)
63
- %end;
64
- %else %if &table_ref=MAXKEYTABLE %then %do;
65
- %mddl_dc_maxkeytable(libds=&outds)
66
- %end;
67
-
68
- %if &libds=0 %then %do;
69
- proc sql;
70
- describe table &syslast;
71
- drop table &syslast;
72
- %end;
73
- %mend mp_coretable;
@@ -1,405 +0,0 @@
1
- /**
2
- @file mp_getddl.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.
7
-
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_getddl(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)
28
- @param [in] fref= (getddl) the fileref to which to _append_ the DDL. If it
29
- does not exist, it will be created.
30
- @param [in] flavour= (SAS) The type of DDL to create. Options:
31
- @li SAS
32
- @li TSQL
33
-
34
- @param [in]showlog= (NO) Set to YES to show the DDL in the log
35
- @param [in] schema= () Choose a preferred schema name (default is to use
36
- actual schema, else libref)
37
- @param [in] applydttm= (NO) For non SAS DDL, choose if columns are created
38
- with native datetime2 format or regular decimal type
39
-
40
- @version 9.3
41
- @author Allan Bowe
42
- **/
43
-
44
- %macro mp_getddl(libref,ds,fref=getddl,flavour=SAS,showlog=NO,schema=
45
- ,applydttm=NO
46
- )/*/STORE SOURCE*/;
47
-
48
- /* check fileref is assigned */
49
- %if %mf_existfileref(&fref)=0 %then %do;
50
- filename &fref temp ;
51
- %end;
52
-
53
- %if %length(&libref)=0 %then %let libref=WORK;
54
- %let flavour=%upcase(&flavour);
55
-
56
- proc sql noprint;
57
- create table _data_ as
58
- select * from dictionary.tables
59
- where upcase(libname)="%upcase(&libref)"
60
- and memtype='DATA' /* views not currently supported */
61
- %if %length(&ds)>0 %then %do;
62
- and upcase(memname)="%upcase(&ds)"
63
- %end;
64
- ;
65
- %local tabinfo; %let tabinfo=&syslast;
66
-
67
- create table _data_ as
68
- select * from dictionary.columns
69
- where upcase(libname)="%upcase(&libref)"
70
- %if %length(&ds)>0 %then %do;
71
- and upcase(memname)="%upcase(&ds)"
72
- %end;
73
- ;
74
- %local colinfo; %let colinfo=&syslast;
75
-
76
- %local dsnlist;
77
- select distinct upcase(memname) into: dsnlist
78
- separated by ' '
79
- from &syslast
80
- ;
81
-
82
- create table _data_ as
83
- select * from dictionary.indexes
84
- where upcase(libname)="%upcase(&libref)"
85
- %if %length(&ds)>0 %then %do;
86
- and upcase(memname)="%upcase(&ds)"
87
- %end;
88
- order by idxusage, indxname, indxpos
89
- ;
90
- %local idxinfo; %let idxinfo=&syslast;
91
-
92
- /* Extract all Primary Key and Unique data constraints */
93
- %mp_getconstraints(lib=%upcase(&libref),ds=%upcase(&ds),outds=_data_)
94
- %local colconst; %let colconst=&syslast;
95
-
96
- %macro addConst();
97
- %global constraints_used;
98
- data _null_;
99
- length ctype $11 constraint_name_orig $256 constraints_used $5000;
100
- set &colconst(
101
- where=(table_name="&curds" and constraint_type in ('PRIMARY','UNIQUE'))
102
- ) end=last;
103
- file &fref mod;
104
- by constraint_type constraint_name;
105
- retain constraints_used;
106
- constraint_name_orig=constraint_name;
107
- if upcase(strip(constraint_type)) = 'PRIMARY' then ctype='PRIMARY KEY';
108
- else ctype=strip(constraint_type);
109
- %if &flavour=TSQL %then %do;
110
- column_name=catt('[',column_name,']');
111
- constraint_name=catt('[',constraint_name,']');
112
- %end;
113
- %else %if &flavour=PGSQL %then %do;
114
- column_name=catt('"',column_name,'"');
115
- constraint_name=catt('"',constraint_name,'"');
116
- %end;
117
- if first.constraint_name then do;
118
- constraints_used = catx(' ', constraints_used, constraint_name_orig);
119
- put " ,CONSTRAINT " constraint_name ctype "(" ;
120
- put ' ' column_name;
121
- end;
122
- else put ' ,' column_name;
123
- if last.constraint_name then do;
124
- put " )";
125
- call symput('constraints_used',strip(constraints_used));
126
- end;
127
- run;
128
- %put &=constraints_used;
129
- %mend addConst;
130
-
131
- data _null_;
132
- file &fref mod;
133
- put "/* DDL generated by &sysuserid on %sysfunc(datetime(),datetime19.) */";
134
- run;
135
-
136
- %local x curds;
137
- %if &flavour=SAS %then %do;
138
- %do x=1 %to %sysfunc(countw(&dsnlist));
139
- %let curds=%scan(&dsnlist,&x);
140
- data _null_;
141
- file &fref mod;
142
- put "/* SAS Flavour DDL for %upcase(&libref).&curds */";
143
- put "proc sql;";
144
- run;
145
- data _null_;
146
- file &fref mod;
147
- length lab $1024 typ $20;
148
- set &colinfo (where=(upcase(memname)="&curds")) end=last;
149
-
150
- if _n_=1 then do;
151
- if memtype='DATA' then do;
152
- put "create table &libref..&curds(";
153
- end;
154
- else do;
155
- /* just a placeholder - we filter out views at the top */
156
- put "create view &libref..&curds(";
157
- end;
158
- put " "@@;
159
- end;
160
- else put " ,"@@;
161
- if length(format)>1 then fmt=" format="!!cats(format);
162
- if length(label)>1 then
163
- lab=" label="!!cats("'",tranwrd(label,"'","''"),"'");
164
- if notnull='yes' then notnul=' not null';
165
- if type='char' then typ=cats('char(',length,')');
166
- else if length ne 8 then typ='num length='!!cats(length);
167
- else typ='num';
168
- put name typ fmt notnul lab;
169
- run;
170
-
171
- /* Extra step for data constraints */
172
- %addConst()
173
-
174
- data _null_;
175
- file &fref mod;
176
- put ');';
177
- run;
178
-
179
- /* Create Unique Indexes, but only if they were not already defined within
180
- the Constraints section. */
181
- data _null_;
182
- *length ds $128;
183
- set &idxinfo(
184
- where=(
185
- memname="&curds"
186
- and unique='yes'
187
- and indxname not in (
188
- %sysfunc(tranwrd("&constraints_used",%str( ),%str(",")))
189
- )
190
- )
191
- );
192
- file &fref mod;
193
- by idxusage indxname;
194
- /* ds=cats(libname,'.',memname); */
195
- if first.indxname then do;
196
- put 'CREATE UNIQUE INDEX ' indxname "ON &libref..&curds (" ;
197
- put ' ' name ;
198
- end;
199
- else put ' ,' name ;
200
- *else put ' ,' name ;
201
- if last.indxname then do;
202
- put ');';
203
- end;
204
- run;
205
-
206
- /*
207
- ods output IntegrityConstraints=ic;
208
- proc contents data=testali out2=info;
209
- run;
210
- */
211
- %end;
212
- %end;
213
- %else %if &flavour=TSQL %then %do;
214
- /* if schema does not exist, set to be same as libref */
215
- %local schemaactual;
216
- proc sql noprint;
217
- select sysvalue into: schemaactual
218
- from dictionary.libnames
219
- where upcase(libname)="&libref" and engine='SQLSVR';
220
- %let schema=%sysfunc(coalescec(&schemaactual,&schema,&libref));
221
-
222
- %do x=1 %to %sysfunc(countw(&dsnlist));
223
- %let curds=%scan(&dsnlist,&x);
224
- data _null_;
225
- file &fref mod;
226
- put "/* TSQL Flavour DDL for &schema..&curds */";
227
- data _null_;
228
- file &fref mod;
229
- set &colinfo (where=(upcase(memname)="&curds")) end=last;
230
- if _n_=1 then do;
231
- if memtype='DATA' then do;
232
- put "create table [&schema].[&curds](";
233
- end;
234
- else do;
235
- /* just a placeholder - we filter out views at the top */
236
- put "create view [&schema].[&curds](";
237
- end;
238
- put " "@@;
239
- end;
240
- else put " ,"@@;
241
- format=upcase(format);
242
- if 1=0 then; /* dummy if */
243
- %if &applydttm=YES %then %do;
244
- else if format=:'DATETIME' then fmt='[datetime2](7) ';
245
- %end;
246
- else if type='num' then fmt='[decimal](18,2)';
247
- else if length le 8000 then fmt='[varchar]('!!cats(length)!!')';
248
- else fmt=cats('[varchar](max)');
249
- if notnull='yes' then notnul=' NOT NULL';
250
- put "[" name +(-1) "]" fmt notnul;
251
- run;
252
-
253
- /* Extra step for data constraints */
254
- %addConst()
255
-
256
- /* Create Unique Indexes, but only if they were not already defined within
257
- the Constraints section. */
258
- data _null_;
259
- *length ds $128;
260
- set &idxinfo(
261
- where=(
262
- memname="&curds"
263
- and unique='yes'
264
- and indxname not in (
265
- %sysfunc(tranwrd("&constraints_used",%str( ),%str(",")))
266
- )
267
- )
268
- );
269
- file &fref mod;
270
- by idxusage indxname;
271
- *ds=cats(libname,'.',memname);
272
- if first.indxname then do;
273
- /* add nonclustered in case of multiple unique indexes */
274
- put ' ,index [' indxname +(-1) '] UNIQUE NONCLUSTERED (';
275
- put ' [' name +(-1) ']';
276
- end;
277
- else put ' ,[' name +(-1) ']';
278
- if last.indxname then do;
279
- put ' )';
280
- end;
281
- run;
282
-
283
- data _null_;
284
- file &fref mod;
285
- put ')';
286
- put 'GO';
287
- run;
288
-
289
- /* add extended properties for labels */
290
- data _null_;
291
- file &fref mod;
292
- length nm $64 lab $1024;
293
- set &colinfo (where=(upcase(memname)="&curds" and label ne '')) end=last;
294
- nm=cats("N'",tranwrd(name,"'","''"),"'");
295
- lab=cats("N'",tranwrd(label,"'","''"),"'");
296
- put ' ';
297
- put "EXEC sys.sp_addextendedproperty ";
298
- put " @name=N'MS_Description',@value=" lab ;
299
- put " ,@level0type=N'SCHEMA',@level0name=N'&schema' ";
300
- put " ,@level1type=N'TABLE',@level1name=N'&curds'";
301
- put " ,@level2type=N'COLUMN',@level2name=" nm ;
302
- if last then put 'GO';
303
- run;
304
- %end;
305
- %end;
306
- %else %if &flavour=PGSQL %then %do;
307
- /* if schema does not exist, set to be same as libref */
308
- %local schemaactual;
309
- proc sql noprint;
310
- select sysvalue into: schemaactual
311
- from dictionary.libnames
312
- where upcase(libname)="&libref" and engine='POSTGRES';
313
- %let schema=%sysfunc(coalescec(&schemaactual,&schema,&libref));
314
- data _null_;
315
- file &fref mod;
316
- put "CREATE SCHEMA &schema;";
317
- %do x=1 %to %sysfunc(countw(&dsnlist));
318
- %let curds=%scan(&dsnlist,&x);
319
- %local curdsvarcount;
320
- %let curdsvarcount=%mf_getvarcount(&libref..&curds);
321
- %if &curdsvarcount>1600 %then %do;
322
- data _null_;
323
- file &fref mod;
324
- put "/* &libref..&curds contains &curdsvarcount vars */";
325
- put "/* Postgres cannot create tables with over 1600 vars */";
326
- put "/* No DDL will be generated for this table";
327
- run;
328
- %end;
329
- %else %do;
330
- data _null_;
331
- file &fref mod;
332
- put "/* Postgres Flavour DDL for &schema..&curds */";
333
- data _null_;
334
- file &fref mod;
335
- set &colinfo (where=(upcase(memname)="&curds")) end=last;
336
- length fmt $32;
337
- if _n_=1 then do;
338
- if memtype='DATA' then do;
339
- put "CREATE TABLE &schema..&curds (";
340
- end;
341
- else do;
342
- /* just a placeholder - we filter out views at the top */
343
- put "CREATE VIEW &schema..&curds (";
344
- end;
345
- put " "@@;
346
- end;
347
- else put " ,"@@;
348
- format=upcase(format);
349
- if 1=0 then; /* dummy if */
350
- %if &applydttm=YES %then %do;
351
- else if format=:'DATETIME' then fmt=' TIMESTAMP ';
352
- %end;
353
- else if type='num' then fmt=' DOUBLE PRECISION';
354
- else fmt='VARCHAR('!!cats(length)!!')';
355
- if notnull='yes' then notnul=' NOT NULL';
356
- /* quote column names in case they represent reserved words */
357
- name2=quote(trim(name));
358
- put name2 fmt notnul;
359
- run;
360
-
361
- /* Extra step for data constraints */
362
- %addConst()
363
-
364
- data _null_;
365
- file &fref mod;
366
- put ');';
367
- run;
368
-
369
- /* Create Unique Indexes, but only if they were not already defined within
370
- the Constraints section. */
371
- data _null_;
372
- *length ds $128;
373
- set &idxinfo(
374
- where=(
375
- memname="&curds"
376
- and unique='yes'
377
- and indxname not in (
378
- %sysfunc(tranwrd("&constraints_used",%str( ),%str(",")))
379
- )
380
- )
381
- );
382
- file &fref mod;
383
- by idxusage indxname;
384
- if first.indxname then do;
385
- put 'CREATE UNIQUE INDEX "' indxname +(-1) '" ' "ON &schema..&curds(";
386
- put ' "' name +(-1) '"' ;
387
- end;
388
- else put ' ,"' name +(-1) '"';
389
- if last.indxname then do;
390
- put ');';
391
- end;
392
- run;
393
- %end;
394
- %end;
395
- %end;
396
- %if %upcase(&showlog)=YES %then %do;
397
- options ps=max;
398
- data _null_;
399
- infile &fref;
400
- input;
401
- putlog _infile_;
402
- run;
403
- %end;
404
-
405
- %mend mp_getddl;