mirror of
https://github.com/sasjs/core.git
synced 2026-01-13 19:40:06 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03962c2a50 | ||
|
|
6d2fc7e265 | ||
|
|
39b2e7c5f9 |
25
all.sas
25
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.
|
||||||
@@ -4419,8 +4420,8 @@ run;
|
|||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
/* check fileref is assigned */
|
/* check fileref is assigned */
|
||||||
%if %mf_existfileref(&outref)=0 %then %do;
|
%if %mf_existfileref(&fref)=0 %then %do;
|
||||||
filename &outref temp ;
|
filename &fref temp ;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if %length(&libref)=0 %then %let libref=WORK;
|
%if %length(&libref)=0 %then %let libref=WORK;
|
||||||
@@ -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;
|
||||||
@@ -5158,8 +5168,7 @@ create table &outds (rename=(
|
|||||||
@li mf_getvartype.sas
|
@li mf_getvartype.sas
|
||||||
|
|
||||||
@param [in] libds dataset to hash
|
@param [in] libds dataset to hash
|
||||||
@param [in] salt= Provide a salt (could be, for instance, the name of the
|
@param [in] salt= Provide a salt (could be, for instance, the dataset name)
|
||||||
dataset). Max 32 chars.
|
|
||||||
@param [out] outds= (work.mf_hashdataset) The output dataset to create. This
|
@param [out] outds= (work.mf_hashdataset) The output dataset to create. This
|
||||||
will contain one column (hashkey) with one observation (a hex32.
|
will contain one column (hashkey) with one observation (a hex32.
|
||||||
representation of the input hash)
|
representation of the input hash)
|
||||||
@@ -5194,7 +5203,7 @@ create table &outds (rename=(
|
|||||||
%let varlist=%mf_getvarlist(&libds);
|
%let varlist=%mf_getvarlist(&libds);
|
||||||
data &outds(rename=(&keyvar=hashkey) keep=&keyvar);
|
data &outds(rename=(&keyvar=hashkey) keep=&keyvar);
|
||||||
length &prevkeyvar &keyvar $32;
|
length &prevkeyvar &keyvar $32;
|
||||||
retain &prevkeyvar "&salt";
|
retain &prevkeyvar "%sysfunc(md5(%str(&salt)),$hex32.)";
|
||||||
set &libds end=&lastvar;
|
set &libds end=&lastvar;
|
||||||
/* hash should include previous row */
|
/* hash should include previous row */
|
||||||
&keyvar=put(md5(&prevkeyvar
|
&keyvar=put(md5(&prevkeyvar
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -38,8 +39,8 @@
|
|||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
/* check fileref is assigned */
|
/* check fileref is assigned */
|
||||||
%if %mf_existfileref(&outref)=0 %then %do;
|
%if %mf_existfileref(&fref)=0 %then %do;
|
||||||
filename &outref temp ;
|
filename &fref temp ;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if %length(&libref)=0 %then %let libref=WORK;
|
%if %length(&libref)=0 %then %let libref=WORK;
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -20,8 +20,7 @@
|
|||||||
@li mf_getvartype.sas
|
@li mf_getvartype.sas
|
||||||
|
|
||||||
@param [in] libds dataset to hash
|
@param [in] libds dataset to hash
|
||||||
@param [in] salt= Provide a salt (could be, for instance, the name of the
|
@param [in] salt= Provide a salt (could be, for instance, the dataset name)
|
||||||
dataset). Max 32 chars.
|
|
||||||
@param [out] outds= (work.mf_hashdataset) The output dataset to create. This
|
@param [out] outds= (work.mf_hashdataset) The output dataset to create. This
|
||||||
will contain one column (hashkey) with one observation (a hex32.
|
will contain one column (hashkey) with one observation (a hex32.
|
||||||
representation of the input hash)
|
representation of the input hash)
|
||||||
@@ -56,7 +55,7 @@
|
|||||||
%let varlist=%mf_getvarlist(&libds);
|
%let varlist=%mf_getvarlist(&libds);
|
||||||
data &outds(rename=(&keyvar=hashkey) keep=&keyvar);
|
data &outds(rename=(&keyvar=hashkey) keep=&keyvar);
|
||||||
length &prevkeyvar &keyvar $32;
|
length &prevkeyvar &keyvar $32;
|
||||||
retain &prevkeyvar "&salt";
|
retain &prevkeyvar "%sysfunc(md5(%str(&salt)),$hex32.)";
|
||||||
set &libds end=&lastvar;
|
set &libds end=&lastvar;
|
||||||
/* hash should include previous row */
|
/* hash should include previous row */
|
||||||
&keyvar=put(md5(&prevkeyvar
|
&keyvar=put(md5(&prevkeyvar
|
||||||
|
|||||||
23
tests/base/mp_getddl.test.sas
Normal file
23
tests/base/mp_getddl.test.sas
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing mp_getddl.sas macro
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mp_getddl.sas
|
||||||
|
@li mp_assert.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
data test(index=(pk=(x y)/unique /nomiss));
|
||||||
|
x=1;
|
||||||
|
y='blah';
|
||||||
|
label x='blah';
|
||||||
|
run;
|
||||||
|
proc sql; describe table &syslast;
|
||||||
|
%mp_getddl(work,test,flavour=tsql,showlog=YES)
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(&syscc=0),
|
||||||
|
desc=mp_getddl runs without errors,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user