1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-05 00:20:05 +00:00

Compare commits

...

2 Commits

3 changed files with 152 additions and 132 deletions

32
all.sas
View File

@@ -3444,9 +3444,9 @@ run;
located. If not provided, is ignored. located. If not provided, is ignored.
@param [out] outds= (0) The output table to load. If not provided, will @param [out] outds= (0) The output table to load. If not provided, will
default to the table in the &ds parameter. default to the table in the &ds parameter.
@param [in] flavour= (BASE) The SQL flavour to be applied to the output. Valid @param [in] flavour= (SAS) The SQL flavour to be applied to the output. Valid
options: options:
@li BASE (default) - suitable for regular proc sql @li SAS (default) - suitable for regular proc sql
@li PGSQL - Used for Postgres databases @li PGSQL - Used for Postgres databases
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@@ -3459,7 +3459,7 @@ run;
@author Allan Bowe (credit mjsq) @author Allan Bowe (credit mjsq)
**/ **/
%macro mp_ds2inserts(ds, outref=0,outlib=0,outds=0,flavour=BASE %macro mp_ds2inserts(ds, outref=0,outlib=0,outds=0,flavour=SAS
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%if not %sysfunc(exist(&ds)) %then %do; %if not %sysfunc(exist(&ds)) %then %do;
@@ -3475,7 +3475,7 @@ run;
%if %index(&ds,.)=0 %then %let ds=WORK.&ds; %if %index(&ds,.)=0 %then %let ds=WORK.&ds;
%let flavour=%upcase(&flavour); %let flavour=%upcase(&flavour);
%if &flavour ne BASE and &flavour ne PGSQL %then %do; %if &flavour ne SAS and &flavour ne PGSQL %then %do;
%put %str(WAR)NING: &flavour is not supported; %put %str(WAR)NING: &flavour is not supported;
%return; %return;
%end; %end;
@@ -3529,7 +3529,7 @@ data _null_;
%let var=%scan(&varlist,&i); %let var=%scan(&varlist,&i);
%let vtype=%mf_getvartype(&ds,&var); %let vtype=%mf_getvartype(&ds,&var);
%if &i=1 %then %do; %if &i=1 %then %do;
%if &flavour=BASE %then %do; %if &flavour=SAS %then %do;
put "insert into &outlib.&outds set "; put "insert into &outlib.&outds set ";
put " &var="@; put " &var="@;
%end; %end;
@@ -3544,7 +3544,7 @@ data _null_;
%end; %end;
%end; %end;
%else %do; %else %do;
%if &flavour=BASE %then %do; %if &flavour=SAS %then %do;
put " ,&var="@; put " ,&var="@;
%end; %end;
%else %if &flavour=PGSQL %then %do; %else %if &flavour=PGSQL %then %do;
@@ -3552,7 +3552,7 @@ data _null_;
%end; %end;
%end; %end;
%if &vtype=N %then %do; %if &vtype=N %then %do;
%if &flavour=BASE %then %do; %if &flavour=SAS %then %do;
put &var; put &var;
%end; %end;
%else %if &flavour=PGSQL %then %do; %else %if &flavour=PGSQL %then %do;
@@ -3565,7 +3565,7 @@ data _null_;
put _____str; put _____str;
%end; %end;
%end; %end;
%if &flavour=BASE %then %do; %if &flavour=SAS %then %do;
put ';'; put ';';
%end; %end;
%else %if &flavour=PGSQL %then %do; %else %if &flavour=PGSQL %then %do;
@@ -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,6 +4686,17 @@ 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);
%local curdsvarcount;
%let curdsvarcount=%mf_getvarcount(&libref..&curds);
%if &curdsvarcount>1600 %then %do;
data _null_;
file &fref mod;
put "/* &libref..&curds contains &curdsvarcount vars */";
put "/* Postgres cannot create tables with over 1600 vars */";
put "/* No DDL will be generated for this table";
run;
%end;
%else %do;
data _null_; data _null_;
file &fref mod; file &fref mod;
put "/* Postgres Flavour DDL for &schema..&curds */"; put "/* Postgres Flavour DDL for &schema..&curds */";
@@ -4738,18 +4750,16 @@ run;
); );
file &fref mod; file &fref mod;
by idxusage indxname; by idxusage indxname;
/* ds=cats(libname,'.',memname); */
if first.indxname then do; 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;

View File

@@ -20,9 +20,9 @@
located. If not provided, is ignored. located. If not provided, is ignored.
@param [out] outds= (0) The output table to load. If not provided, will @param [out] outds= (0) The output table to load. If not provided, will
default to the table in the &ds parameter. default to the table in the &ds parameter.
@param [in] flavour= (BASE) The SQL flavour to be applied to the output. Valid @param [in] flavour= (SAS) The SQL flavour to be applied to the output. Valid
options: options:
@li BASE (default) - suitable for regular proc sql @li SAS (default) - suitable for regular proc sql
@li PGSQL - Used for Postgres databases @li PGSQL - Used for Postgres databases
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@@ -35,7 +35,7 @@
@author Allan Bowe (credit mjsq) @author Allan Bowe (credit mjsq)
**/ **/
%macro mp_ds2inserts(ds, outref=0,outlib=0,outds=0,flavour=BASE %macro mp_ds2inserts(ds, outref=0,outlib=0,outds=0,flavour=SAS
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%if not %sysfunc(exist(&ds)) %then %do; %if not %sysfunc(exist(&ds)) %then %do;
@@ -51,7 +51,7 @@
%if %index(&ds,.)=0 %then %let ds=WORK.&ds; %if %index(&ds,.)=0 %then %let ds=WORK.&ds;
%let flavour=%upcase(&flavour); %let flavour=%upcase(&flavour);
%if &flavour ne BASE and &flavour ne PGSQL %then %do; %if &flavour ne SAS and &flavour ne PGSQL %then %do;
%put %str(WAR)NING: &flavour is not supported; %put %str(WAR)NING: &flavour is not supported;
%return; %return;
%end; %end;
@@ -105,7 +105,7 @@ data _null_;
%let var=%scan(&varlist,&i); %let var=%scan(&varlist,&i);
%let vtype=%mf_getvartype(&ds,&var); %let vtype=%mf_getvartype(&ds,&var);
%if &i=1 %then %do; %if &i=1 %then %do;
%if &flavour=BASE %then %do; %if &flavour=SAS %then %do;
put "insert into &outlib.&outds set "; put "insert into &outlib.&outds set ";
put " &var="@; put " &var="@;
%end; %end;
@@ -120,7 +120,7 @@ data _null_;
%end; %end;
%end; %end;
%else %do; %else %do;
%if &flavour=BASE %then %do; %if &flavour=SAS %then %do;
put " ,&var="@; put " ,&var="@;
%end; %end;
%else %if &flavour=PGSQL %then %do; %else %if &flavour=PGSQL %then %do;
@@ -128,7 +128,7 @@ data _null_;
%end; %end;
%end; %end;
%if &vtype=N %then %do; %if &vtype=N %then %do;
%if &flavour=BASE %then %do; %if &flavour=SAS %then %do;
put &var; put &var;
%end; %end;
%else %if &flavour=PGSQL %then %do; %else %if &flavour=PGSQL %then %do;
@@ -141,7 +141,7 @@ data _null_;
put _____str; put _____str;
%end; %end;
%end; %end;
%if &flavour=BASE %then %do; %if &flavour=SAS %then %do;
put ';'; put ';';
%end; %end;
%else %if &flavour=PGSQL %then %do; %else %if &flavour=PGSQL %then %do;

View File

@@ -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,6 +305,17 @@ 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);
%local curdsvarcount;
%let curdsvarcount=%mf_getvarcount(&libref..&curds);
%if &curdsvarcount>1600 %then %do;
data _null_;
file &fref mod;
put "/* &libref..&curds contains &curdsvarcount vars */";
put "/* Postgres cannot create tables with over 1600 vars */";
put "/* No DDL will be generated for this table";
run;
%end;
%else %do;
data _null_; data _null_;
file &fref mod; file &fref mod;
put "/* Postgres Flavour DDL for &schema..&curds */"; put "/* Postgres Flavour DDL for &schema..&curds */";
@@ -357,18 +369,16 @@ run;
); );
file &fref mod; file &fref mod;
by idxusage indxname; by idxusage indxname;
/* ds=cats(libname,'.',memname); */
if first.indxname then do; 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;