mirror of
https://github.com/sasjs/core.git
synced 2026-01-03 23:50:06 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03962c2a50 |
126
all.sas
126
all.sas
@@ -4398,6 +4398,7 @@ run;
|
|||||||
|
|
||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
@li mf_existfileref.sas
|
@li mf_existfileref.sas
|
||||||
|
@li mf_getvarcount.sas
|
||||||
@li mp_getconstraints.sas
|
@li mp_getconstraints.sas
|
||||||
|
|
||||||
@param lib libref of the library to create DDL for. Should be assigned.
|
@param lib libref of the library to create DDL for. Should be assigned.
|
||||||
@@ -4685,71 +4686,80 @@ run;
|
|||||||
put "CREATE SCHEMA &schema;";
|
put "CREATE SCHEMA &schema;";
|
||||||
%do x=1 %to %sysfunc(countw(&dsnlist));
|
%do x=1 %to %sysfunc(countw(&dsnlist));
|
||||||
%let curds=%scan(&dsnlist,&x);
|
%let curds=%scan(&dsnlist,&x);
|
||||||
data _null_;
|
%local curdsvarcount;
|
||||||
file &fref mod;
|
%let curdsvarcount=%mf_getvarcount(&libref..&curds);
|
||||||
put "/* Postgres Flavour DDL for &schema..&curds */";
|
%if &curdsvarcount>1600 %then %do;
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fref mod;
|
file &fref mod;
|
||||||
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
put "/* &libref..&curds contains &curdsvarcount vars */";
|
||||||
length fmt $32;
|
put "/* Postgres cannot create tables with over 1600 vars */";
|
||||||
if _n_=1 then do;
|
put "/* No DDL will be generated for this table";
|
||||||
if memtype='DATA' then do;
|
run;
|
||||||
put "CREATE TABLE &schema..&curds (";
|
%end;
|
||||||
|
%else %do;
|
||||||
|
data _null_;
|
||||||
|
file &fref mod;
|
||||||
|
put "/* Postgres Flavour DDL for &schema..&curds */";
|
||||||
|
data _null_;
|
||||||
|
file &fref mod;
|
||||||
|
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
||||||
|
length fmt $32;
|
||||||
|
if _n_=1 then do;
|
||||||
|
if memtype='DATA' then do;
|
||||||
|
put "CREATE TABLE &schema..&curds (";
|
||||||
|
end;
|
||||||
|
else do;
|
||||||
|
put "CREATE VIEW &schema..&curds (";
|
||||||
|
end;
|
||||||
|
put " "@@;
|
||||||
end;
|
end;
|
||||||
else do;
|
else put " ,"@@;
|
||||||
put "CREATE VIEW &schema..&curds (";
|
format=upcase(format);
|
||||||
end;
|
if 1=0 then; /* dummy if */
|
||||||
put " "@@;
|
%if &applydttm=YES %then %do;
|
||||||
end;
|
else if format=:'DATETIME' then fmt=' TIMESTAMP ';
|
||||||
else put " ,"@@;
|
%end;
|
||||||
format=upcase(format);
|
else if type='num' then fmt=' DOUBLE PRECISION';
|
||||||
if 1=0 then; /* dummy if */
|
else fmt='VARCHAR('!!cats(length)!!')';
|
||||||
%if &applydttm=YES %then %do;
|
if notnull='yes' then notnul=' NOT NULL';
|
||||||
else if format=:'DATETIME' then fmt=' TIMESTAMP ';
|
/* quote column names in case they represent reserved words */
|
||||||
%end;
|
name2=quote(trim(name));
|
||||||
else if type='num' then fmt=' DOUBLE PRECISION';
|
put name2 fmt notnul;
|
||||||
else fmt='VARCHAR('!!cats(length)!!')';
|
run;
|
||||||
if notnull='yes' then notnul=' NOT NULL';
|
|
||||||
/* quote column names in case they represent reserved words */
|
|
||||||
name2=quote(trim(name));
|
|
||||||
put name2 fmt notnul;
|
|
||||||
run;
|
|
||||||
|
|
||||||
/* Extra step for data constraints */
|
/* Extra step for data constraints */
|
||||||
%addConst()
|
%addConst()
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fref mod;
|
file &fref mod;
|
||||||
put ');';
|
put ');';
|
||||||
run;
|
run;
|
||||||
|
|
||||||
/* Create Unique Indexes, but only if they were not already defined within
|
/* Create Unique Indexes, but only if they were not already defined within
|
||||||
the Constraints section. */
|
the Constraints section. */
|
||||||
data _null_;
|
data _null_;
|
||||||
*length ds $128;
|
*length ds $128;
|
||||||
set &idxinfo(
|
set &idxinfo(
|
||||||
where=(
|
where=(
|
||||||
memname="&curds"
|
memname="&curds"
|
||||||
and unique='yes'
|
and unique='yes'
|
||||||
and indxname not in (
|
and indxname not in (
|
||||||
%sysfunc(tranwrd("&constraints_used",%str( ),%str(",")))
|
%sysfunc(tranwrd("&constraints_used",%str( ),%str(",")))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
);
|
||||||
);
|
file &fref mod;
|
||||||
file &fref mod;
|
by idxusage indxname;
|
||||||
by idxusage indxname;
|
if first.indxname then do;
|
||||||
/* ds=cats(libname,'.',memname); */
|
|
||||||
if first.indxname then do;
|
|
||||||
put 'CREATE UNIQUE INDEX "' indxname +(-1) '" ' "ON &schema..&curds(";
|
put 'CREATE UNIQUE INDEX "' indxname +(-1) '" ' "ON &schema..&curds(";
|
||||||
put ' "' name +(-1) '"' ;
|
put ' "' name +(-1) '"' ;
|
||||||
end;
|
end;
|
||||||
else put ' ,"' name +(-1) '"';
|
else put ' ,"' name +(-1) '"';
|
||||||
*else put ' ,' name ;
|
if last.indxname then do;
|
||||||
if last.indxname then do;
|
put ');';
|
||||||
put ');';
|
end;
|
||||||
end;
|
run;
|
||||||
run;
|
%end;
|
||||||
|
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%if %upcase(&showlog)=YES %then %do;
|
%if %upcase(&showlog)=YES %then %do;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
@li mf_existfileref.sas
|
@li mf_existfileref.sas
|
||||||
|
@li mf_getvarcount.sas
|
||||||
@li mp_getconstraints.sas
|
@li mp_getconstraints.sas
|
||||||
|
|
||||||
@param lib libref of the library to create DDL for. Should be assigned.
|
@param lib libref of the library to create DDL for. Should be assigned.
|
||||||
@@ -304,71 +305,80 @@ run;
|
|||||||
put "CREATE SCHEMA &schema;";
|
put "CREATE SCHEMA &schema;";
|
||||||
%do x=1 %to %sysfunc(countw(&dsnlist));
|
%do x=1 %to %sysfunc(countw(&dsnlist));
|
||||||
%let curds=%scan(&dsnlist,&x);
|
%let curds=%scan(&dsnlist,&x);
|
||||||
data _null_;
|
%local curdsvarcount;
|
||||||
file &fref mod;
|
%let curdsvarcount=%mf_getvarcount(&libref..&curds);
|
||||||
put "/* Postgres Flavour DDL for &schema..&curds */";
|
%if &curdsvarcount>1600 %then %do;
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fref mod;
|
file &fref mod;
|
||||||
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
put "/* &libref..&curds contains &curdsvarcount vars */";
|
||||||
length fmt $32;
|
put "/* Postgres cannot create tables with over 1600 vars */";
|
||||||
if _n_=1 then do;
|
put "/* No DDL will be generated for this table";
|
||||||
if memtype='DATA' then do;
|
run;
|
||||||
put "CREATE TABLE &schema..&curds (";
|
%end;
|
||||||
|
%else %do;
|
||||||
|
data _null_;
|
||||||
|
file &fref mod;
|
||||||
|
put "/* Postgres Flavour DDL for &schema..&curds */";
|
||||||
|
data _null_;
|
||||||
|
file &fref mod;
|
||||||
|
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
||||||
|
length fmt $32;
|
||||||
|
if _n_=1 then do;
|
||||||
|
if memtype='DATA' then do;
|
||||||
|
put "CREATE TABLE &schema..&curds (";
|
||||||
|
end;
|
||||||
|
else do;
|
||||||
|
put "CREATE VIEW &schema..&curds (";
|
||||||
|
end;
|
||||||
|
put " "@@;
|
||||||
end;
|
end;
|
||||||
else do;
|
else put " ,"@@;
|
||||||
put "CREATE VIEW &schema..&curds (";
|
format=upcase(format);
|
||||||
end;
|
if 1=0 then; /* dummy if */
|
||||||
put " "@@;
|
%if &applydttm=YES %then %do;
|
||||||
end;
|
else if format=:'DATETIME' then fmt=' TIMESTAMP ';
|
||||||
else put " ,"@@;
|
%end;
|
||||||
format=upcase(format);
|
else if type='num' then fmt=' DOUBLE PRECISION';
|
||||||
if 1=0 then; /* dummy if */
|
else fmt='VARCHAR('!!cats(length)!!')';
|
||||||
%if &applydttm=YES %then %do;
|
if notnull='yes' then notnul=' NOT NULL';
|
||||||
else if format=:'DATETIME' then fmt=' TIMESTAMP ';
|
/* quote column names in case they represent reserved words */
|
||||||
%end;
|
name2=quote(trim(name));
|
||||||
else if type='num' then fmt=' DOUBLE PRECISION';
|
put name2 fmt notnul;
|
||||||
else fmt='VARCHAR('!!cats(length)!!')';
|
run;
|
||||||
if notnull='yes' then notnul=' NOT NULL';
|
|
||||||
/* quote column names in case they represent reserved words */
|
|
||||||
name2=quote(trim(name));
|
|
||||||
put name2 fmt notnul;
|
|
||||||
run;
|
|
||||||
|
|
||||||
/* Extra step for data constraints */
|
/* Extra step for data constraints */
|
||||||
%addConst()
|
%addConst()
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fref mod;
|
file &fref mod;
|
||||||
put ');';
|
put ');';
|
||||||
run;
|
run;
|
||||||
|
|
||||||
/* Create Unique Indexes, but only if they were not already defined within
|
/* Create Unique Indexes, but only if they were not already defined within
|
||||||
the Constraints section. */
|
the Constraints section. */
|
||||||
data _null_;
|
data _null_;
|
||||||
*length ds $128;
|
*length ds $128;
|
||||||
set &idxinfo(
|
set &idxinfo(
|
||||||
where=(
|
where=(
|
||||||
memname="&curds"
|
memname="&curds"
|
||||||
and unique='yes'
|
and unique='yes'
|
||||||
and indxname not in (
|
and indxname not in (
|
||||||
%sysfunc(tranwrd("&constraints_used",%str( ),%str(",")))
|
%sysfunc(tranwrd("&constraints_used",%str( ),%str(",")))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
);
|
||||||
);
|
file &fref mod;
|
||||||
file &fref mod;
|
by idxusage indxname;
|
||||||
by idxusage indxname;
|
if first.indxname then do;
|
||||||
/* ds=cats(libname,'.',memname); */
|
|
||||||
if first.indxname then do;
|
|
||||||
put 'CREATE UNIQUE INDEX "' indxname +(-1) '" ' "ON &schema..&curds(";
|
put 'CREATE UNIQUE INDEX "' indxname +(-1) '" ' "ON &schema..&curds(";
|
||||||
put ' "' name +(-1) '"' ;
|
put ' "' name +(-1) '"' ;
|
||||||
end;
|
end;
|
||||||
else put ' ,"' name +(-1) '"';
|
else put ' ,"' name +(-1) '"';
|
||||||
*else put ' ,' name ;
|
if last.indxname then do;
|
||||||
if last.indxname then do;
|
put ');';
|
||||||
put ');';
|
end;
|
||||||
end;
|
run;
|
||||||
run;
|
%end;
|
||||||
|
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%if %upcase(&showlog)=YES %then %do;
|
%if %upcase(&showlog)=YES %then %do;
|
||||||
|
|||||||
Reference in New Issue
Block a user