mirror of
https://github.com/sasjs/core.git
synced 2025-12-14 07:54:35 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8beec7dc19 | ||
|
|
e3f6cb7b45 | ||
|
|
041aff9bc0 | ||
|
|
1986732573 | ||
|
|
958f509894 | ||
|
|
1373957031 | ||
|
|
8466acc7a7 | ||
|
|
45e646565f | ||
|
|
9d9a72220f | ||
|
|
53865a3909 |
12
.editorconfig
Normal file
12
.editorconfig
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# http://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = false
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
node_modules
|
node_modules
|
||||||
|
.DS_Store
|
||||||
70
all.sas
70
all.sas
@@ -2653,7 +2653,72 @@ run;
|
|||||||
run;
|
run;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
%else %if &flavour=PGSQL %then %do;
|
||||||
|
/* if schema does not exist, set to be same as libref */
|
||||||
|
%local schemaactual;
|
||||||
|
proc sql noprint;
|
||||||
|
select sysvalue into: schemaactual
|
||||||
|
from dictionary.libnames
|
||||||
|
where libname="&libref" and engine='POSTGRES';
|
||||||
|
%let schema=%sysfunc(coalescec(&schemaactual,&schema,&libref));
|
||||||
|
|
||||||
|
%do x=1 %to %sysfunc(countw(&dsnlist));
|
||||||
|
%let curds=%scan(&dsnlist,&x);
|
||||||
|
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;
|
||||||
|
else put " ,"@@;
|
||||||
|
format=upcase(format);
|
||||||
|
if 1=0 then; /* dummy if */
|
||||||
|
%if &applydttm=YES %then %do;
|
||||||
|
else if format=:'DATETIME' then fmt=' TIMESTAMP ';
|
||||||
|
%end;
|
||||||
|
else if type='num' then fmt=' DOUBLE PRECISION';
|
||||||
|
else fmt='VARCHAR('!!cats(length)!!')';
|
||||||
|
if notnull='yes' then notnul=' NOT NULL';
|
||||||
|
put name fmt notnul;
|
||||||
|
run;
|
||||||
|
data _null_;
|
||||||
|
length ds $128;
|
||||||
|
set &idxinfo (where=(memname="&curds"));
|
||||||
|
file &fref mod;
|
||||||
|
by idxusage indxname;
|
||||||
|
if unique='yes' then uniq=' unique';
|
||||||
|
ds=cats(libname,'.',memname);
|
||||||
|
if first.indxname then do;
|
||||||
|
if unique='yes' and nomiss='yes' then do;
|
||||||
|
put ' ,PRIMARY KEY ';
|
||||||
|
end;
|
||||||
|
else if unique='yes' then do;
|
||||||
|
/* add nonclustered in case of multiple unique indexes */
|
||||||
|
put ' ,UNIQUE ';
|
||||||
|
end;
|
||||||
|
put ' (' name ;
|
||||||
|
end;
|
||||||
|
else put ' ,' name ;
|
||||||
|
if last.indxname then do;
|
||||||
|
put ' )';
|
||||||
|
end;
|
||||||
|
run;
|
||||||
|
data _null_;
|
||||||
|
file &fref mod;
|
||||||
|
put ');';
|
||||||
|
run;
|
||||||
|
%end;
|
||||||
|
%end;
|
||||||
%if &showlog=YES %then %do;
|
%if &showlog=YES %then %do;
|
||||||
options ps=max;
|
options ps=max;
|
||||||
data _null_;
|
data _null_;
|
||||||
@@ -4158,7 +4223,7 @@ ods package publish archive properties
|
|||||||
ods package close;
|
ods package close;
|
||||||
|
|
||||||
%mend;/**
|
%mend;/**
|
||||||
@file
|
@file mm_adduser2group.sas
|
||||||
@brief Adds a user to a group
|
@brief Adds a user to a group
|
||||||
@details Adds a user to a metadata group. The macro first checks whether the
|
@details Adds a user to a metadata group. The macro first checks whether the
|
||||||
user is in that group, and if not, the user is added.
|
user is in that group, and if not, the user is added.
|
||||||
@@ -4171,6 +4236,7 @@ ods package close;
|
|||||||
|
|
||||||
@param user= the user name (not displayname)
|
@param user= the user name (not displayname)
|
||||||
@param group= the group to which to add the user
|
@param group= the group to which to add the user
|
||||||
|
@param mdebug= set to 1 to show debug info in log
|
||||||
|
|
||||||
@warning the macro does not check inherited group memberships - it looks at
|
@warning the macro does not check inherited group memberships - it looks at
|
||||||
direct members only
|
direct members only
|
||||||
@@ -4227,7 +4293,7 @@ run;
|
|||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if %length(&syscc) ge 4 %then %do;
|
%if &syscc ge 4 %then %do;
|
||||||
%put WARNING: SYSCC=&syscc, exiting &sysmacroname;
|
%put WARNING: SYSCC=&syscc, exiting &sysmacroname;
|
||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
|
|||||||
@@ -13,11 +13,13 @@
|
|||||||
label x='blah';
|
label x='blah';
|
||||||
run;
|
run;
|
||||||
proc sql; describe table &syslast;
|
proc sql; describe table &syslast;
|
||||||
|
|
||||||
%mp_getddl(work,test,flavour=tsql,showlog=YES)
|
%mp_getddl(work,test,flavour=tsql,showlog=YES)
|
||||||
|
|
||||||
|
<h4> Dependencies </h4>
|
||||||
|
@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.
|
||||||
@param ds dataset to create ddl for
|
@param ds dataset to create ddl for (optional)
|
||||||
@param fref= the fileref to which to write the DDL. If not preassigned, will
|
@param fref= the fileref to which to write the DDL. If not preassigned, will
|
||||||
be assigned to TEMP.
|
be assigned to TEMP.
|
||||||
@param flavour= The type of DDL to create (default=SAS). Supported=TSQL
|
@param flavour= The type of DDL to create (default=SAS). Supported=TSQL
|
||||||
@@ -26,11 +28,9 @@
|
|||||||
,else libref)
|
,else libref)
|
||||||
@param applydttm= for non SAS DDL, choose if columns are created with native
|
@param applydttm= for non SAS DDL, choose if columns are created with native
|
||||||
datetime2 format or regular decimal type
|
datetime2 format or regular decimal type
|
||||||
|
|
||||||
@version 9.3
|
@version 9.3
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@source https://github.com/sasjs/core
|
@source https://github.com/sasjs/core
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mp_getddl(libref,ds,fref=getddl,flavour=SAS,showlog=NO,schema=
|
%macro mp_getddl(libref,ds,fref=getddl,flavour=SAS,showlog=NO,schema=
|
||||||
@@ -54,16 +54,6 @@ create table _data_ as
|
|||||||
;
|
;
|
||||||
%local tabinfo; %let tabinfo=&syslast;
|
%local tabinfo; %let tabinfo=&syslast;
|
||||||
|
|
||||||
create table _data_ as
|
|
||||||
select * from dictionary.indexes
|
|
||||||
where upcase(libname)="%upcase(&libref)"
|
|
||||||
%if %length(&ds)>0 %then %do;
|
|
||||||
and upcase(memname)="%upcase(&ds)"
|
|
||||||
%end;
|
|
||||||
order by idxusage, indxname, indxpos
|
|
||||||
;
|
|
||||||
%local idxinfo; %let idxinfo=&syslast;
|
|
||||||
|
|
||||||
create table _data_ as
|
create table _data_ as
|
||||||
select * from dictionary.columns
|
select * from dictionary.columns
|
||||||
where upcase(libname)="%upcase(&libref)"
|
where upcase(libname)="%upcase(&libref)"
|
||||||
@@ -72,10 +62,43 @@ create table _data_ as
|
|||||||
%end;
|
%end;
|
||||||
;
|
;
|
||||||
%local colinfo; %let colinfo=&syslast;
|
%local colinfo; %let colinfo=&syslast;
|
||||||
|
|
||||||
%local dsnlist;
|
%local dsnlist;
|
||||||
select distinct upcase(memname) into: dsnlist
|
select distinct upcase(memname) into: dsnlist
|
||||||
separated by ' '
|
separated by ' '
|
||||||
from &syslast;
|
from &syslast
|
||||||
|
;
|
||||||
|
quit;
|
||||||
|
|
||||||
|
/* Extract all Primary Key and Unique data constraints */
|
||||||
|
%mp_getconstraints(lib=%upcase(&libref),ds=%upcase(&ds),outds=_data_)
|
||||||
|
%local colconst; %let colconst=&syslast;
|
||||||
|
|
||||||
|
%macro addConst();
|
||||||
|
data _null_;
|
||||||
|
length ctype $11;
|
||||||
|
set &colconst (where=(table_name="&curds" and constraint_type in ('PRIMARY','UNIQUE'))) end=last;
|
||||||
|
file &fref mod;
|
||||||
|
by constraint_type constraint_name;
|
||||||
|
if upcase(strip(constraint_type)) = 'PRIMARY' then ctype='PRIMARY KEY';
|
||||||
|
else ctype=strip(constraint_type);
|
||||||
|
%if &flavour=TSQL %then %do;
|
||||||
|
column_name=catt('[',column_name,']');
|
||||||
|
constraint_name=catt('[',constraint_name,']');
|
||||||
|
%end;
|
||||||
|
%else %if &flavour=PGSQL %then %do;
|
||||||
|
column_name=catt('"',column_name,'"');
|
||||||
|
constraint_name=catt('"',constraint_name,'"');
|
||||||
|
%end;
|
||||||
|
if first.constraint_name then do;
|
||||||
|
put " ,CONSTRAINT " constraint_name ctype "(" ;
|
||||||
|
put ' ' column_name;
|
||||||
|
end;
|
||||||
|
else put ' ,' column_name;
|
||||||
|
if last.constraint_name then put " )";
|
||||||
|
run;
|
||||||
|
%mend;
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fref;
|
file &fref;
|
||||||
put "/* DDL generated by &sysuserid on %sysfunc(datetime(),datetime19.) */";
|
put "/* DDL generated by &sysuserid on %sysfunc(datetime(),datetime19.) */";
|
||||||
@@ -84,13 +107,14 @@ run;
|
|||||||
%local x curds;
|
%local x curds;
|
||||||
%if &flavour=SAS %then %do;
|
%if &flavour=SAS %then %do;
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fref;
|
file &fref mod;
|
||||||
put "proc sql;";
|
put "proc sql;";
|
||||||
run;
|
run;
|
||||||
%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_;
|
data _null_;
|
||||||
file &fref mod;
|
file &fref mod;
|
||||||
|
if _n_ eq 1 then put "/* SAS Flavour DDL for %upcase(&libref).&curds */";
|
||||||
length nm lab $1024;
|
length nm lab $1024;
|
||||||
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
||||||
|
|
||||||
@@ -109,22 +133,14 @@ run;
|
|||||||
lab=" label="!!quote(trim(label));
|
lab=" label="!!quote(trim(label));
|
||||||
if notnull='yes' then notnul=' not null';
|
if notnull='yes' then notnul=' not null';
|
||||||
put name type len fmt notnul lab;
|
put name type len fmt notnul lab;
|
||||||
if last then put ');';
|
|
||||||
run;
|
run;
|
||||||
|
|
||||||
|
/* Extra step for data constraints */
|
||||||
|
%addConst()
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
length ds $128;
|
|
||||||
set &idxinfo (where=(memname="&curds")) end=last;
|
|
||||||
file &fref mod;
|
file &fref mod;
|
||||||
by idxusage indxname;
|
put ');';
|
||||||
if unique='yes' then uniq=' unique';
|
|
||||||
ds=cats(libname,'.',memname);
|
|
||||||
if first.indxname then do;
|
|
||||||
put 'create ' uniq ' index ' indxname;
|
|
||||||
put ' on ' ds '(' name @@;
|
|
||||||
end;
|
|
||||||
else put ',' name @@;
|
|
||||||
if last.indxname then put ');';
|
|
||||||
run;
|
run;
|
||||||
/*
|
/*
|
||||||
ods output IntegrityConstraints=ic;
|
ods output IntegrityConstraints=ic;
|
||||||
@@ -146,7 +162,7 @@ run;
|
|||||||
%let curds=%scan(&dsnlist,&x);
|
%let curds=%scan(&dsnlist,&x);
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fref mod;
|
file &fref mod;
|
||||||
put "/* DDL for &schema..&curds */";
|
put "/* TSQL Flavour DDL for &schema..&curds */";
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fref mod;
|
file &fref mod;
|
||||||
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
set &colinfo (where=(upcase(memname)="&curds")) end=last;
|
||||||
@@ -169,31 +185,12 @@ run;
|
|||||||
else if length le 8000 then fmt='[varchar]('!!cats(length)!!')';
|
else if length le 8000 then fmt='[varchar]('!!cats(length)!!')';
|
||||||
else fmt=cats('[varchar](max)');
|
else fmt=cats('[varchar](max)');
|
||||||
if notnull='yes' then notnul=' NOT NULL';
|
if notnull='yes' then notnul=' NOT NULL';
|
||||||
put name fmt notnul;
|
put "[" name +(-1) "]" fmt notnul;
|
||||||
run;
|
|
||||||
data _null_;
|
|
||||||
length ds $128;
|
|
||||||
set &idxinfo (where=(memname="&curds"));
|
|
||||||
file &fref mod;
|
|
||||||
by idxusage indxname;
|
|
||||||
if unique='yes' then uniq=' unique';
|
|
||||||
ds=cats(libname,'.',memname);
|
|
||||||
if first.indxname then do;
|
|
||||||
if unique='yes' and nomiss='yes' then do;
|
|
||||||
put ' ,constraint [' indxname '] PRIMARY KEY';
|
|
||||||
end;
|
|
||||||
else if unique='yes' then do;
|
|
||||||
/* add nonclustered in case of multiple unique indexes */
|
|
||||||
put ' ,index [' indxname '] UNIQUE NONCLUSTERED';
|
|
||||||
end;
|
|
||||||
put ' (';
|
|
||||||
put ' [' name ']';
|
|
||||||
end;
|
|
||||||
else put ' ,[' name ']';
|
|
||||||
if last.indxname then do;
|
|
||||||
put ' )';
|
|
||||||
end;
|
|
||||||
run;
|
run;
|
||||||
|
|
||||||
|
/* Extra step for data constraints */
|
||||||
|
%addConst()
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fref mod;
|
file &fref mod;
|
||||||
put ')';
|
put ')';
|
||||||
@@ -217,7 +214,55 @@ run;
|
|||||||
run;
|
run;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
%else %if &flavour=PGSQL %then %do;
|
||||||
|
/* if schema does not exist, set to be same as libref */
|
||||||
|
%local schemaactual;
|
||||||
|
proc sql noprint;
|
||||||
|
select sysvalue into: schemaactual
|
||||||
|
from dictionary.libnames
|
||||||
|
where libname="&libref" and engine='POSTGRES';
|
||||||
|
%let schema=%sysfunc(coalescec(&schemaactual,&schema,&libref));
|
||||||
|
|
||||||
|
%do x=1 %to %sysfunc(countw(&dsnlist));
|
||||||
|
%let curds=%scan(&dsnlist,&x);
|
||||||
|
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;
|
||||||
|
else put " ,"@@;
|
||||||
|
format=upcase(format);
|
||||||
|
if 1=0 then; /* dummy if */
|
||||||
|
%if &applydttm=YES %then %do;
|
||||||
|
else if format=:'DATETIME' then fmt=' TIMESTAMP ';
|
||||||
|
%end;
|
||||||
|
else if type='num' then fmt=' DOUBLE PRECISION';
|
||||||
|
else fmt='VARCHAR('!!cats(length)!!')';
|
||||||
|
if notnull='yes' then notnul=' NOT NULL';
|
||||||
|
put name fmt notnul;
|
||||||
|
run;
|
||||||
|
|
||||||
|
/* Extra step for data constraints */
|
||||||
|
%addConst()
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
file &fref mod;
|
||||||
|
put ');';
|
||||||
|
run;
|
||||||
|
|
||||||
|
%end;
|
||||||
|
%end;
|
||||||
%if &showlog=YES %then %do;
|
%if &showlog=YES %then %do;
|
||||||
options ps=max;
|
options ps=max;
|
||||||
data _null_;
|
data _null_;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ doxygen Doxyfile
|
|||||||
# refresh github pages site
|
# refresh github pages site
|
||||||
git clone git@github.com:sasjs/core.github.io.git
|
git clone git@github.com:sasjs/core.github.io.git
|
||||||
cd core.github.io
|
cd core.github.io
|
||||||
git rm -r *
|
rm -r *
|
||||||
mv $BUILD_FOLDER/out/doxy/* .
|
mv $BUILD_FOLDER/out/doxy/* .
|
||||||
echo 'core.sasjs.io' > CNAME
|
echo 'core.sasjs.io' > CNAME
|
||||||
git add *
|
git add *
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
@file
|
@file mm_adduser2group.sas
|
||||||
@brief Adds a user to a group
|
@brief Adds a user to a group
|
||||||
@details Adds a user to a metadata group. The macro first checks whether the
|
@details Adds a user to a metadata group. The macro first checks whether the
|
||||||
user is in that group, and if not, the user is added.
|
user is in that group, and if not, the user is added.
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
@param user= the user name (not displayname)
|
@param user= the user name (not displayname)
|
||||||
@param group= the group to which to add the user
|
@param group= the group to which to add the user
|
||||||
|
@param mdebug= set to 1 to show debug info in log
|
||||||
|
|
||||||
@warning the macro does not check inherited group memberships - it looks at
|
@warning the macro does not check inherited group memberships - it looks at
|
||||||
direct members only
|
direct members only
|
||||||
@@ -68,7 +69,7 @@ run;
|
|||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if %length(&syscc) ge 4 %then %do;
|
%if &syscc ge 4 %then %do;
|
||||||
%put WARNING: SYSCC=&syscc, exiting &sysmacroname;
|
%put WARNING: SYSCC=&syscc, exiting &sysmacroname;
|
||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
|
|||||||
Reference in New Issue
Block a user