mirror of
https://github.com/sasjs/core.git
synced 2025-12-12 06:54:35 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd18d1d5a8 | ||
|
|
fc8a39bbca | ||
|
|
8beec7dc19 | ||
|
|
e3f6cb7b45 | ||
|
|
041aff9bc0 | ||
|
|
1986732573 | ||
|
|
958f509894 | ||
|
|
1373957031 | ||
|
|
8466acc7a7 | ||
|
|
45e646565f | ||
|
|
9d9a72220f | ||
|
|
53865a3909 | ||
|
|
98a0d185ff | ||
|
|
888e07468c | ||
|
|
f491fa3ef5 |
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
|
||||||
244
all.sas
244
all.sas
@@ -2449,11 +2449,13 @@ create table &outds as
|
|||||||
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
|
||||||
@@ -2462,11 +2464,9 @@ create table &outds as
|
|||||||
,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=
|
||||||
@@ -2490,16 +2490,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)"
|
||||||
@@ -2508,10 +2498,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.) */";
|
||||||
@@ -2520,13 +2543,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;
|
||||||
|
|
||||||
@@ -2545,22 +2569,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;
|
||||||
@@ -2582,7 +2598,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;
|
||||||
@@ -2605,31 +2621,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 ')';
|
||||||
@@ -2653,7 +2650,59 @@ 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));
|
||||||
|
data _null_;
|
||||||
|
file &fref mod;
|
||||||
|
put "CREATE SCHEMA &schema;";
|
||||||
|
%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';
|
||||||
|
/* quote column names in case they represent reserved words */
|
||||||
|
name2=quote(trim(name));
|
||||||
|
put name2 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_;
|
||||||
@@ -2663,8 +2712,7 @@ run;
|
|||||||
run;
|
run;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%mend;
|
%mend;/**
|
||||||
/**
|
|
||||||
@file mp_getmaxvarlengths.sas
|
@file mp_getmaxvarlengths.sas
|
||||||
@brief Scans a dataset to find the max length of the variable values
|
@brief Scans a dataset to find the max length of the variable values
|
||||||
@details
|
@details
|
||||||
@@ -3080,7 +3128,9 @@ create table &outds (rename=(
|
|||||||
* PROCJSON (default)
|
* PROCJSON (default)
|
||||||
* DATASTEP
|
* DATASTEP
|
||||||
|
|
||||||
@param dbg= Typically used with an _debug (numeric) option
|
@param dbg= DEPRECATED - was used to conditionally add PRETTY to
|
||||||
|
proc json but this can cause line truncation in large files.
|
||||||
|
|
||||||
|
|
||||||
@version 9.2
|
@version 9.2
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -3106,9 +3156,8 @@ create table &outds (rename=(
|
|||||||
proc sql;drop table &tempds;
|
proc sql;drop table &tempds;
|
||||||
data &tempds /view=&tempds;set &ds;
|
data &tempds /view=&tempds;set &ds;
|
||||||
%if &fmt=N %then format _numeric_ best32.;;
|
%if &fmt=N %then format _numeric_ best32.;;
|
||||||
proc json out=&jref
|
proc json out=&jref pretty
|
||||||
%if &action=ARR %then nokeys ;
|
%if &action=ARR %then nokeys ;
|
||||||
%if &dbg ge 131 %then pretty ;
|
|
||||||
;export &tempds / nosastags fmtnumeric;
|
;export &tempds / nosastags fmtnumeric;
|
||||||
run;
|
run;
|
||||||
proc sql;drop view &tempds;
|
proc sql;drop view &tempds;
|
||||||
@@ -4099,19 +4148,20 @@ 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.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
%mm_adduser2group(user=sasdemo
|
%mm_adduser2group(user=sasdemo
|
||||||
,group=someGroup)
|
,group=someGroup)
|
||||||
|
|
||||||
|
|
||||||
@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
|
||||||
@@ -4168,7 +4218,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;
|
||||||
@@ -6053,9 +6103,8 @@ data _null_;
|
|||||||
put ' proc sql;drop table &tempds; ';
|
put ' proc sql;drop table &tempds; ';
|
||||||
put ' data &tempds /view=&tempds;set &ds; ';
|
put ' data &tempds /view=&tempds;set &ds; ';
|
||||||
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
||||||
put ' proc json out=&jref ';
|
put ' proc json out=&jref pretty ';
|
||||||
put ' %if &action=ARR %then nokeys ; ';
|
put ' %if &action=ARR %then nokeys ; ';
|
||||||
put ' %if &dbg ge 131 %then pretty ; ';
|
|
||||||
put ' ;export &tempds / nosastags fmtnumeric; ';
|
put ' ;export &tempds / nosastags fmtnumeric; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
put ' proc sql;drop view &tempds; ';
|
put ' proc sql;drop view &tempds; ';
|
||||||
@@ -6150,7 +6199,8 @@ data _null_;
|
|||||||
put '%end; ';
|
put '%end; ';
|
||||||
put '%mend; ';
|
put '%mend; ';
|
||||||
put '%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y); ';
|
put '%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y); ';
|
||||||
put '%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug; ';
|
put '%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug ';
|
||||||
|
put ' sasjs_tables; ';
|
||||||
put '%local i tempds; ';
|
put '%local i tempds; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
put '%if &action=FETCH %then %do; ';
|
put '%if &action=FETCH %then %do; ';
|
||||||
@@ -6177,6 +6227,7 @@ data _null_;
|
|||||||
put ' if _n_<20 then putlog _infile_; ';
|
put ' if _n_<20 then putlog _infile_; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
|
put ' %let sasjs_tables=&sasjs_tables &&_webin_name&i; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put '%end; ';
|
put '%end; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
@@ -9188,7 +9239,8 @@ run;
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y);
|
%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y);
|
||||||
%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug;
|
%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug
|
||||||
|
sasjs_tables;
|
||||||
%local i tempds;
|
%local i tempds;
|
||||||
|
|
||||||
%if &action=FETCH %then %do;
|
%if &action=FETCH %then %do;
|
||||||
@@ -9215,6 +9267,7 @@ run;
|
|||||||
if _n_<20 then putlog _infile_;
|
if _n_<20 then putlog _infile_;
|
||||||
%end;
|
%end;
|
||||||
run;
|
run;
|
||||||
|
%let sasjs_tables=&sasjs_tables &&_webin_name&i;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
@@ -9836,9 +9889,8 @@ data _null_;
|
|||||||
put ' proc sql;drop table &tempds; ';
|
put ' proc sql;drop table &tempds; ';
|
||||||
put ' data &tempds /view=&tempds;set &ds; ';
|
put ' data &tempds /view=&tempds;set &ds; ';
|
||||||
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
||||||
put ' proc json out=&jref ';
|
put ' proc json out=&jref pretty ';
|
||||||
put ' %if &action=ARR %then nokeys ; ';
|
put ' %if &action=ARR %then nokeys ; ';
|
||||||
put ' %if &dbg ge 131 %then pretty ; ';
|
|
||||||
put ' ;export &tempds / nosastags fmtnumeric; ';
|
put ' ;export &tempds / nosastags fmtnumeric; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
put ' proc sql;drop view &tempds; ';
|
put ' proc sql;drop view &tempds; ';
|
||||||
@@ -9933,7 +9985,8 @@ data _null_;
|
|||||||
put '%end; ';
|
put '%end; ';
|
||||||
put '%mend; ';
|
put '%mend; ';
|
||||||
put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y); ';
|
put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y); ';
|
||||||
put '%global _webin_file_count _webin_fileuri _debug _omittextlog ; ';
|
put '%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name ';
|
||||||
|
put ' sasjs_tables SYS_JES_JOB_URI; ';
|
||||||
put '%if %index("&_debug",log) %then %let _debug=131; ';
|
put '%if %index("&_debug",log) %then %let _debug=131; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
put '%local i tempds; ';
|
put '%local i tempds; ';
|
||||||
@@ -9947,11 +10000,11 @@ data _null_;
|
|||||||
put ' %if not %symexist(_webin_fileuri1) %then %do; ';
|
put ' %if not %symexist(_webin_fileuri1) %then %do; ';
|
||||||
put ' %let _webin_file_count=%eval(&_webin_file_count+0); ';
|
put ' %let _webin_file_count=%eval(&_webin_file_count+0); ';
|
||||||
put ' %let _webin_fileuri1=&_webin_fileuri; ';
|
put ' %let _webin_fileuri1=&_webin_fileuri; ';
|
||||||
|
put ' %let _webin_name1=&_webin_name; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
put ' %if %symexist(sasjs_tables) %then %do; ';
|
put ' /* if the sasjs_tables param is passed, we expect param based upload */ ';
|
||||||
put ' /* small volumes of non-special data are sent as params for responsiveness */ ';
|
put ' %if %length(&sasjs_tables.XX)>2 %then %do; ';
|
||||||
put ' /* to do - deal with escaped values */ ';
|
|
||||||
put ' filename _sasjs "%sysfunc(pathname(work))/sasjs.lua"; ';
|
put ' filename _sasjs "%sysfunc(pathname(work))/sasjs.lua"; ';
|
||||||
put ' data _null_; ';
|
put ' data _null_; ';
|
||||||
put ' file _sasjs; ';
|
put ' file _sasjs; ';
|
||||||
@@ -10030,13 +10083,19 @@ data _null_;
|
|||||||
put ' infile indata firstobs=2 dsd termstr=crlf ; ';
|
put ' infile indata firstobs=2 dsd termstr=crlf ; ';
|
||||||
put ' input &input_statement; ';
|
put ' input &input_statement; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
|
put ' %let sasjs_tables=&sasjs_tables &&_webin_name&i; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put '%end; ';
|
put '%end; ';
|
||||||
put '%else %if &action=OPEN %then %do; ';
|
put '%else %if &action=OPEN %then %do; ';
|
||||||
put ' /* setup webout */ ';
|
put ' /* setup webout */ ';
|
||||||
put ' OPTIONS NOBOMFILE; ';
|
put ' OPTIONS NOBOMFILE; ';
|
||||||
put ' filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" ';
|
put ' %if "X&SYS_JES_JOB_URI.X"="XX" %then %do; ';
|
||||||
put ' name="_webout.json" lrecl=999999 mod; ';
|
put ' filename _webout temp lrecl=999999 mod; ';
|
||||||
|
put ' %end; ';
|
||||||
|
put ' %else %do; ';
|
||||||
|
put ' filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" ';
|
||||||
|
put ' name="_webout.json" lrecl=999999 mod; ';
|
||||||
|
put ' %end; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
put ' /* setup temp ref */ ';
|
put ' /* setup temp ref */ ';
|
||||||
put ' %if %upcase(&fref) ne _WEBOUT %then %do; ';
|
put ' %if %upcase(&fref) ne _WEBOUT %then %do; ';
|
||||||
@@ -10066,13 +10125,13 @@ data _null_;
|
|||||||
put ' i+1; ';
|
put ' i+1; ';
|
||||||
put ' call symputx(''wt''!!left(i),name); ';
|
put ' call symputx(''wt''!!left(i),name); ';
|
||||||
put ' call symputx(''wtcnt'',i); ';
|
put ' call symputx(''wtcnt'',i); ';
|
||||||
put ' data _null_; file &fref; put ",""WORK"":{"; ';
|
put ' data _null_; file &fref mod; put ",""WORK"":{"; ';
|
||||||
put ' %do i=1 %to &wtcnt; ';
|
put ' %do i=1 %to &wtcnt; ';
|
||||||
put ' %let wt=&&wt&i; ';
|
put ' %let wt=&&wt&i; ';
|
||||||
put ' proc contents noprint data=&wt ';
|
put ' proc contents noprint data=&wt ';
|
||||||
put ' out=_data_ (keep=name type length format:); ';
|
put ' out=_data_ (keep=name type length format:); ';
|
||||||
put ' run;%let tempds=%scan(&syslast,2,.); ';
|
put ' run;%let tempds=%scan(&syslast,2,.); ';
|
||||||
put ' data _null_; file &fref; ';
|
put ' data _null_; file &fref mod; ';
|
||||||
put ' dsid=open("WORK.&wt",''is''); ';
|
put ' dsid=open("WORK.&wt",''is''); ';
|
||||||
put ' nlobs=attrn(dsid,''NLOBS''); ';
|
put ' nlobs=attrn(dsid,''NLOBS''); ';
|
||||||
put ' nvars=attrn(dsid,''NVARS''); ';
|
put ' nvars=attrn(dsid,''NVARS''); ';
|
||||||
@@ -10083,9 +10142,9 @@ data _null_;
|
|||||||
put ' put '',"nvars":'' nvars; ';
|
put ' put '',"nvars":'' nvars; ';
|
||||||
put ' %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP) ';
|
put ' %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP) ';
|
||||||
put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP) ';
|
put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP) ';
|
||||||
put ' data _null_; file &fref;put "}"; ';
|
put ' data _null_; file &fref mod;put "}"; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' data _null_; file &fref;put "}";run; ';
|
put ' data _null_; file &fref mod;put "}";run; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
put ' /* close off json */ ';
|
put ' /* close off json */ ';
|
||||||
@@ -11954,7 +12013,8 @@ filename &fref1 clear;
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y);
|
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y);
|
||||||
%global _webin_file_count _webin_fileuri _debug _omittextlog ;
|
%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name
|
||||||
|
sasjs_tables SYS_JES_JOB_URI;
|
||||||
%if %index("&_debug",log) %then %let _debug=131;
|
%if %index("&_debug",log) %then %let _debug=131;
|
||||||
|
|
||||||
%local i tempds;
|
%local i tempds;
|
||||||
@@ -11968,11 +12028,11 @@ filename &fref1 clear;
|
|||||||
%if not %symexist(_webin_fileuri1) %then %do;
|
%if not %symexist(_webin_fileuri1) %then %do;
|
||||||
%let _webin_file_count=%eval(&_webin_file_count+0);
|
%let _webin_file_count=%eval(&_webin_file_count+0);
|
||||||
%let _webin_fileuri1=&_webin_fileuri;
|
%let _webin_fileuri1=&_webin_fileuri;
|
||||||
|
%let _webin_name1=&_webin_name;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if %symexist(sasjs_tables) %then %do;
|
/* if the sasjs_tables param is passed, we expect param based upload */
|
||||||
/* small volumes of non-special data are sent as params for responsiveness */
|
%if %length(&sasjs_tables.XX)>2 %then %do;
|
||||||
/* to do - deal with escaped values */
|
|
||||||
filename _sasjs "%sysfunc(pathname(work))/sasjs.lua";
|
filename _sasjs "%sysfunc(pathname(work))/sasjs.lua";
|
||||||
data _null_;
|
data _null_;
|
||||||
file _sasjs;
|
file _sasjs;
|
||||||
@@ -12051,13 +12111,19 @@ filename &fref1 clear;
|
|||||||
infile indata firstobs=2 dsd termstr=crlf ;
|
infile indata firstobs=2 dsd termstr=crlf ;
|
||||||
input &input_statement;
|
input &input_statement;
|
||||||
run;
|
run;
|
||||||
|
%let sasjs_tables=&sasjs_tables &&_webin_name&i;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%else %if &action=OPEN %then %do;
|
%else %if &action=OPEN %then %do;
|
||||||
/* setup webout */
|
/* setup webout */
|
||||||
OPTIONS NOBOMFILE;
|
OPTIONS NOBOMFILE;
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
|
%if "X&SYS_JES_JOB_URI.X"="XX" %then %do;
|
||||||
name="_webout.json" lrecl=999999 mod;
|
filename _webout temp lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
|
||||||
|
name="_webout.json" lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
|
|
||||||
/* setup temp ref */
|
/* setup temp ref */
|
||||||
%if %upcase(&fref) ne _WEBOUT %then %do;
|
%if %upcase(&fref) ne _WEBOUT %then %do;
|
||||||
@@ -12087,13 +12153,13 @@ filename &fref1 clear;
|
|||||||
i+1;
|
i+1;
|
||||||
call symputx('wt'!!left(i),name);
|
call symputx('wt'!!left(i),name);
|
||||||
call symputx('wtcnt',i);
|
call symputx('wtcnt',i);
|
||||||
data _null_; file &fref; put ",""WORK"":{";
|
data _null_; file &fref mod; put ",""WORK"":{";
|
||||||
%do i=1 %to &wtcnt;
|
%do i=1 %to &wtcnt;
|
||||||
%let wt=&&wt&i;
|
%let wt=&&wt&i;
|
||||||
proc contents noprint data=&wt
|
proc contents noprint data=&wt
|
||||||
out=_data_ (keep=name type length format:);
|
out=_data_ (keep=name type length format:);
|
||||||
run;%let tempds=%scan(&syslast,2,.);
|
run;%let tempds=%scan(&syslast,2,.);
|
||||||
data _null_; file &fref;
|
data _null_; file &fref mod;
|
||||||
dsid=open("WORK.&wt",'is');
|
dsid=open("WORK.&wt",'is');
|
||||||
nlobs=attrn(dsid,'NLOBS');
|
nlobs=attrn(dsid,'NLOBS');
|
||||||
nvars=attrn(dsid,'NVARS');
|
nvars=attrn(dsid,'NVARS');
|
||||||
@@ -12104,9 +12170,9 @@ filename &fref1 clear;
|
|||||||
put ',"nvars":' nvars;
|
put ',"nvars":' nvars;
|
||||||
%mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP)
|
%mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP)
|
||||||
%mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP)
|
%mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP)
|
||||||
data _null_; file &fref;put "}";
|
data _null_; file &fref mod;put "}";
|
||||||
%end;
|
%end;
|
||||||
data _null_; file &fref;put "}";run;
|
data _null_; file &fref mod;put "}";run;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* close off json */
|
/* close off json */
|
||||||
|
|||||||
@@ -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,59 @@ 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));
|
||||||
|
data _null_;
|
||||||
|
file &fref mod;
|
||||||
|
put "CREATE SCHEMA &schema;";
|
||||||
|
%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';
|
||||||
|
/* quote column names in case they represent reserved words */
|
||||||
|
name2=quote(trim(name));
|
||||||
|
put name2 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_;
|
||||||
@@ -227,4 +276,4 @@ run;
|
|||||||
run;
|
run;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%mend;
|
%mend;
|
||||||
@@ -40,7 +40,9 @@
|
|||||||
* PROCJSON (default)
|
* PROCJSON (default)
|
||||||
* DATASTEP
|
* DATASTEP
|
||||||
|
|
||||||
@param dbg= Typically used with an _debug (numeric) option
|
@param dbg= DEPRECATED - was used to conditionally add PRETTY to
|
||||||
|
proc json but this can cause line truncation in large files.
|
||||||
|
|
||||||
|
|
||||||
@version 9.2
|
@version 9.2
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -66,9 +68,8 @@
|
|||||||
proc sql;drop table &tempds;
|
proc sql;drop table &tempds;
|
||||||
data &tempds /view=&tempds;set &ds;
|
data &tempds /view=&tempds;set &ds;
|
||||||
%if &fmt=N %then format _numeric_ best32.;;
|
%if &fmt=N %then format _numeric_ best32.;;
|
||||||
proc json out=&jref
|
proc json out=&jref pretty
|
||||||
%if &action=ARR %then nokeys ;
|
%if &action=ARR %then nokeys ;
|
||||||
%if &dbg ge 131 %then pretty ;
|
|
||||||
;export &tempds / nosastags fmtnumeric;
|
;export &tempds / nosastags fmtnumeric;
|
||||||
run;
|
run;
|
||||||
proc sql;drop view &tempds;
|
proc sql;drop view &tempds;
|
||||||
|
|||||||
@@ -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,17 +1,18 @@
|
|||||||
/**
|
/**
|
||||||
@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.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
%mm_adduser2group(user=sasdemo
|
%mm_adduser2group(user=sasdemo
|
||||||
,group=someGroup)
|
,group=someGroup)
|
||||||
|
|
||||||
|
|
||||||
@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;
|
||||||
|
|||||||
@@ -104,9 +104,8 @@ data _null_;
|
|||||||
put ' proc sql;drop table &tempds; ';
|
put ' proc sql;drop table &tempds; ';
|
||||||
put ' data &tempds /view=&tempds;set &ds; ';
|
put ' data &tempds /view=&tempds;set &ds; ';
|
||||||
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
||||||
put ' proc json out=&jref ';
|
put ' proc json out=&jref pretty ';
|
||||||
put ' %if &action=ARR %then nokeys ; ';
|
put ' %if &action=ARR %then nokeys ; ';
|
||||||
put ' %if &dbg ge 131 %then pretty ; ';
|
|
||||||
put ' ;export &tempds / nosastags fmtnumeric; ';
|
put ' ;export &tempds / nosastags fmtnumeric; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
put ' proc sql;drop view &tempds; ';
|
put ' proc sql;drop view &tempds; ';
|
||||||
@@ -201,7 +200,8 @@ data _null_;
|
|||||||
put '%end; ';
|
put '%end; ';
|
||||||
put '%mend; ';
|
put '%mend; ';
|
||||||
put '%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y); ';
|
put '%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y); ';
|
||||||
put '%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug; ';
|
put '%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug ';
|
||||||
|
put ' sasjs_tables; ';
|
||||||
put '%local i tempds; ';
|
put '%local i tempds; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
put '%if &action=FETCH %then %do; ';
|
put '%if &action=FETCH %then %do; ';
|
||||||
@@ -228,6 +228,7 @@ data _null_;
|
|||||||
put ' if _n_<20 then putlog _infile_; ';
|
put ' if _n_<20 then putlog _infile_; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
|
put ' %let sasjs_tables=&sasjs_tables &&_webin_name&i; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put '%end; ';
|
put '%end; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
|
|||||||
@@ -33,7 +33,8 @@
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y);
|
%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y);
|
||||||
%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug;
|
%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug
|
||||||
|
sasjs_tables;
|
||||||
%local i tempds;
|
%local i tempds;
|
||||||
|
|
||||||
%if &action=FETCH %then %do;
|
%if &action=FETCH %then %do;
|
||||||
@@ -60,6 +61,7 @@
|
|||||||
if _n_<20 then putlog _infile_;
|
if _n_<20 then putlog _infile_;
|
||||||
%end;
|
%end;
|
||||||
run;
|
run;
|
||||||
|
%let sasjs_tables=&sasjs_tables &&_webin_name&i;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
|
|||||||
@@ -241,9 +241,8 @@ data _null_;
|
|||||||
put ' proc sql;drop table &tempds; ';
|
put ' proc sql;drop table &tempds; ';
|
||||||
put ' data &tempds /view=&tempds;set &ds; ';
|
put ' data &tempds /view=&tempds;set &ds; ';
|
||||||
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
||||||
put ' proc json out=&jref ';
|
put ' proc json out=&jref pretty ';
|
||||||
put ' %if &action=ARR %then nokeys ; ';
|
put ' %if &action=ARR %then nokeys ; ';
|
||||||
put ' %if &dbg ge 131 %then pretty ; ';
|
|
||||||
put ' ;export &tempds / nosastags fmtnumeric; ';
|
put ' ;export &tempds / nosastags fmtnumeric; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
put ' proc sql;drop view &tempds; ';
|
put ' proc sql;drop view &tempds; ';
|
||||||
@@ -338,7 +337,8 @@ data _null_;
|
|||||||
put '%end; ';
|
put '%end; ';
|
||||||
put '%mend; ';
|
put '%mend; ';
|
||||||
put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y); ';
|
put '%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y); ';
|
||||||
put '%global _webin_file_count _webin_fileuri _debug _omittextlog ; ';
|
put '%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name ';
|
||||||
|
put ' sasjs_tables SYS_JES_JOB_URI; ';
|
||||||
put '%if %index("&_debug",log) %then %let _debug=131; ';
|
put '%if %index("&_debug",log) %then %let _debug=131; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
put '%local i tempds; ';
|
put '%local i tempds; ';
|
||||||
@@ -352,11 +352,11 @@ data _null_;
|
|||||||
put ' %if not %symexist(_webin_fileuri1) %then %do; ';
|
put ' %if not %symexist(_webin_fileuri1) %then %do; ';
|
||||||
put ' %let _webin_file_count=%eval(&_webin_file_count+0); ';
|
put ' %let _webin_file_count=%eval(&_webin_file_count+0); ';
|
||||||
put ' %let _webin_fileuri1=&_webin_fileuri; ';
|
put ' %let _webin_fileuri1=&_webin_fileuri; ';
|
||||||
|
put ' %let _webin_name1=&_webin_name; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
put ' %if %symexist(sasjs_tables) %then %do; ';
|
put ' /* if the sasjs_tables param is passed, we expect param based upload */ ';
|
||||||
put ' /* small volumes of non-special data are sent as params for responsiveness */ ';
|
put ' %if %length(&sasjs_tables.XX)>2 %then %do; ';
|
||||||
put ' /* to do - deal with escaped values */ ';
|
|
||||||
put ' filename _sasjs "%sysfunc(pathname(work))/sasjs.lua"; ';
|
put ' filename _sasjs "%sysfunc(pathname(work))/sasjs.lua"; ';
|
||||||
put ' data _null_; ';
|
put ' data _null_; ';
|
||||||
put ' file _sasjs; ';
|
put ' file _sasjs; ';
|
||||||
@@ -435,13 +435,19 @@ data _null_;
|
|||||||
put ' infile indata firstobs=2 dsd termstr=crlf ; ';
|
put ' infile indata firstobs=2 dsd termstr=crlf ; ';
|
||||||
put ' input &input_statement; ';
|
put ' input &input_statement; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
|
put ' %let sasjs_tables=&sasjs_tables &&_webin_name&i; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put '%end; ';
|
put '%end; ';
|
||||||
put '%else %if &action=OPEN %then %do; ';
|
put '%else %if &action=OPEN %then %do; ';
|
||||||
put ' /* setup webout */ ';
|
put ' /* setup webout */ ';
|
||||||
put ' OPTIONS NOBOMFILE; ';
|
put ' OPTIONS NOBOMFILE; ';
|
||||||
put ' filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" ';
|
put ' %if "X&SYS_JES_JOB_URI.X"="XX" %then %do; ';
|
||||||
put ' name="_webout.json" lrecl=999999 mod; ';
|
put ' filename _webout temp lrecl=999999 mod; ';
|
||||||
|
put ' %end; ';
|
||||||
|
put ' %else %do; ';
|
||||||
|
put ' filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" ';
|
||||||
|
put ' name="_webout.json" lrecl=999999 mod; ';
|
||||||
|
put ' %end; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
put ' /* setup temp ref */ ';
|
put ' /* setup temp ref */ ';
|
||||||
put ' %if %upcase(&fref) ne _WEBOUT %then %do; ';
|
put ' %if %upcase(&fref) ne _WEBOUT %then %do; ';
|
||||||
@@ -471,13 +477,13 @@ data _null_;
|
|||||||
put ' i+1; ';
|
put ' i+1; ';
|
||||||
put ' call symputx(''wt''!!left(i),name); ';
|
put ' call symputx(''wt''!!left(i),name); ';
|
||||||
put ' call symputx(''wtcnt'',i); ';
|
put ' call symputx(''wtcnt'',i); ';
|
||||||
put ' data _null_; file &fref; put ",""WORK"":{"; ';
|
put ' data _null_; file &fref mod; put ",""WORK"":{"; ';
|
||||||
put ' %do i=1 %to &wtcnt; ';
|
put ' %do i=1 %to &wtcnt; ';
|
||||||
put ' %let wt=&&wt&i; ';
|
put ' %let wt=&&wt&i; ';
|
||||||
put ' proc contents noprint data=&wt ';
|
put ' proc contents noprint data=&wt ';
|
||||||
put ' out=_data_ (keep=name type length format:); ';
|
put ' out=_data_ (keep=name type length format:); ';
|
||||||
put ' run;%let tempds=%scan(&syslast,2,.); ';
|
put ' run;%let tempds=%scan(&syslast,2,.); ';
|
||||||
put ' data _null_; file &fref; ';
|
put ' data _null_; file &fref mod; ';
|
||||||
put ' dsid=open("WORK.&wt",''is''); ';
|
put ' dsid=open("WORK.&wt",''is''); ';
|
||||||
put ' nlobs=attrn(dsid,''NLOBS''); ';
|
put ' nlobs=attrn(dsid,''NLOBS''); ';
|
||||||
put ' nvars=attrn(dsid,''NVARS''); ';
|
put ' nvars=attrn(dsid,''NVARS''); ';
|
||||||
@@ -488,9 +494,9 @@ data _null_;
|
|||||||
put ' put '',"nvars":'' nvars; ';
|
put ' put '',"nvars":'' nvars; ';
|
||||||
put ' %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP) ';
|
put ' %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP) ';
|
||||||
put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP) ';
|
put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP) ';
|
||||||
put ' data _null_; file &fref;put "}"; ';
|
put ' data _null_; file &fref mod;put "}"; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' data _null_; file &fref;put "}";run; ';
|
put ' data _null_; file &fref mod;put "}";run; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' ';
|
put ' ';
|
||||||
put ' /* close off json */ ';
|
put ' /* close off json */ ';
|
||||||
|
|||||||
@@ -36,7 +36,8 @@
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y);
|
%macro mv_webout(action,ds,fref=_mvwtemp,dslabel=,fmt=Y);
|
||||||
%global _webin_file_count _webin_fileuri _debug _omittextlog ;
|
%global _webin_file_count _webin_fileuri _debug _omittextlog _webin_name
|
||||||
|
sasjs_tables SYS_JES_JOB_URI;
|
||||||
%if %index("&_debug",log) %then %let _debug=131;
|
%if %index("&_debug",log) %then %let _debug=131;
|
||||||
|
|
||||||
%local i tempds;
|
%local i tempds;
|
||||||
@@ -50,11 +51,11 @@
|
|||||||
%if not %symexist(_webin_fileuri1) %then %do;
|
%if not %symexist(_webin_fileuri1) %then %do;
|
||||||
%let _webin_file_count=%eval(&_webin_file_count+0);
|
%let _webin_file_count=%eval(&_webin_file_count+0);
|
||||||
%let _webin_fileuri1=&_webin_fileuri;
|
%let _webin_fileuri1=&_webin_fileuri;
|
||||||
|
%let _webin_name1=&_webin_name;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if %symexist(sasjs_tables) %then %do;
|
/* if the sasjs_tables param is passed, we expect param based upload */
|
||||||
/* small volumes of non-special data are sent as params for responsiveness */
|
%if %length(&sasjs_tables.XX)>2 %then %do;
|
||||||
/* to do - deal with escaped values */
|
|
||||||
filename _sasjs "%sysfunc(pathname(work))/sasjs.lua";
|
filename _sasjs "%sysfunc(pathname(work))/sasjs.lua";
|
||||||
data _null_;
|
data _null_;
|
||||||
file _sasjs;
|
file _sasjs;
|
||||||
@@ -133,13 +134,19 @@
|
|||||||
infile indata firstobs=2 dsd termstr=crlf ;
|
infile indata firstobs=2 dsd termstr=crlf ;
|
||||||
input &input_statement;
|
input &input_statement;
|
||||||
run;
|
run;
|
||||||
|
%let sasjs_tables=&sasjs_tables &&_webin_name&i;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%else %if &action=OPEN %then %do;
|
%else %if &action=OPEN %then %do;
|
||||||
/* setup webout */
|
/* setup webout */
|
||||||
OPTIONS NOBOMFILE;
|
OPTIONS NOBOMFILE;
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
|
%if "X&SYS_JES_JOB_URI.X"="XX" %then %do;
|
||||||
name="_webout.json" lrecl=999999 mod;
|
filename _webout temp lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
|
||||||
|
name="_webout.json" lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
|
|
||||||
/* setup temp ref */
|
/* setup temp ref */
|
||||||
%if %upcase(&fref) ne _WEBOUT %then %do;
|
%if %upcase(&fref) ne _WEBOUT %then %do;
|
||||||
@@ -169,13 +176,13 @@
|
|||||||
i+1;
|
i+1;
|
||||||
call symputx('wt'!!left(i),name);
|
call symputx('wt'!!left(i),name);
|
||||||
call symputx('wtcnt',i);
|
call symputx('wtcnt',i);
|
||||||
data _null_; file &fref; put ",""WORK"":{";
|
data _null_; file &fref mod; put ",""WORK"":{";
|
||||||
%do i=1 %to &wtcnt;
|
%do i=1 %to &wtcnt;
|
||||||
%let wt=&&wt&i;
|
%let wt=&&wt&i;
|
||||||
proc contents noprint data=&wt
|
proc contents noprint data=&wt
|
||||||
out=_data_ (keep=name type length format:);
|
out=_data_ (keep=name type length format:);
|
||||||
run;%let tempds=%scan(&syslast,2,.);
|
run;%let tempds=%scan(&syslast,2,.);
|
||||||
data _null_; file &fref;
|
data _null_; file &fref mod;
|
||||||
dsid=open("WORK.&wt",'is');
|
dsid=open("WORK.&wt",'is');
|
||||||
nlobs=attrn(dsid,'NLOBS');
|
nlobs=attrn(dsid,'NLOBS');
|
||||||
nvars=attrn(dsid,'NVARS');
|
nvars=attrn(dsid,'NVARS');
|
||||||
@@ -186,9 +193,9 @@
|
|||||||
put ',"nvars":' nvars;
|
put ',"nvars":' nvars;
|
||||||
%mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP)
|
%mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP)
|
||||||
%mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP)
|
%mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP)
|
||||||
data _null_; file &fref;put "}";
|
data _null_; file &fref mod;put "}";
|
||||||
%end;
|
%end;
|
||||||
data _null_; file &fref;put "}";run;
|
data _null_; file &fref mod;put "}";run;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* close off json */
|
/* close off json */
|
||||||
|
|||||||
Reference in New Issue
Block a user