mirror of
https://github.com/sasjs/core.git
synced 2026-01-05 08:30:06 +00:00
chore: formatting in mp_guesspk
This commit is contained in:
30
all.sas
30
all.sas
@@ -2921,9 +2921,9 @@ create table &outds (rename=(
|
|||||||
@brief Guess the primary key of a table
|
@brief Guess the primary key of a table
|
||||||
@details Tries to guess the primary key of a table based on the following logic:
|
@details Tries to guess the primary key of a table based on the following logic:
|
||||||
|
|
||||||
* Columns with nulls are ignored
|
* Columns with nulls are ignored
|
||||||
* Return only column combinations that provide unique results
|
* Return only column combinations that provide unique results
|
||||||
* Start from one column, then move out to include composite keys of 2 to 6 columns
|
* Start from one column, then move out to include composite keys of 2 to 6 columns
|
||||||
|
|
||||||
The library of the target should be assigned before using this macro.
|
The library of the target should be assigned before using this macro.
|
||||||
|
|
||||||
@@ -2969,7 +2969,7 @@ create table &outds (rename=(
|
|||||||
/* get null count and row count */
|
/* get null count and row count */
|
||||||
%let tmpvar=%mf_getuniquename();
|
%let tmpvar=%mf_getuniquename();
|
||||||
proc sql noprint;
|
proc sql noprint;
|
||||||
create table _data_ as select
|
create table _data_ as select
|
||||||
count(*) as &tmpvar
|
count(*) as &tmpvar
|
||||||
%do i=1 %to &vcnt;
|
%do i=1 %to &vcnt;
|
||||||
%let var=%scan(&vars,&i);
|
%let var=%scan(&vars,&i);
|
||||||
@@ -3003,10 +3003,10 @@ create table &outds (rename=(
|
|||||||
%put &sysmacroname: &baseds has no combination of unique records! Exiting.;
|
%put &sysmacroname: &baseds has no combination of unique records! Exiting.;
|
||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* now check cardinality */
|
/* now check cardinality */
|
||||||
proc sql noprint;
|
proc sql noprint;
|
||||||
create table _data_ as select
|
create table _data_ as select
|
||||||
%do i=1 %to &ppkcnt;
|
%do i=1 %to &ppkcnt;
|
||||||
%let var=%scan(&posspks,&i);
|
%let var=%scan(&posspks,&i);
|
||||||
count(distinct &var) as &var
|
count(distinct &var) as &var
|
||||||
@@ -3130,7 +3130,7 @@ create table &outds (rename=(
|
|||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if &ppkcnt=4 %then %do;
|
%if &ppkcnt=4 %then %do;
|
||||||
%put &sysmacroname: No more PK guess possible;
|
%put &sysmacroname: No more PK guess possible;
|
||||||
%return;
|
%return;
|
||||||
@@ -3146,7 +3146,7 @@ create table &outds (rename=(
|
|||||||
%let lev3=%scan(&posspks,&k);
|
%let lev3=%scan(&posspks,&k);
|
||||||
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
|
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
|
||||||
%let lev4=%scan(&posspks,&l);
|
%let lev4=%scan(&posspks,&l);
|
||||||
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
|
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
|
||||||
%do m=5 %to &ppkcnt;
|
%do m=5 %to &ppkcnt;
|
||||||
%let lev5=%scan(&posspks,&m);
|
%let lev5=%scan(&posspks,&m);
|
||||||
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %do;
|
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %do;
|
||||||
@@ -3168,7 +3168,7 @@ create table &outds (rename=(
|
|||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if &ppkcnt=5 %then %do;
|
%if &ppkcnt=5 %then %do;
|
||||||
%put &sysmacroname: No more PK guess possible;
|
%put &sysmacroname: No more PK guess possible;
|
||||||
%return;
|
%return;
|
||||||
@@ -3184,17 +3184,17 @@ create table &outds (rename=(
|
|||||||
%let lev3=%scan(&posspks,&k);
|
%let lev3=%scan(&posspks,&k);
|
||||||
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
|
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
|
||||||
%let lev4=%scan(&posspks,&l);
|
%let lev4=%scan(&posspks,&l);
|
||||||
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
|
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
|
||||||
%do m=5 %to &ppkcnt;
|
%do m=5 %to &ppkcnt;
|
||||||
%let lev5=%scan(&posspks,&m);
|
%let lev5=%scan(&posspks,&m);
|
||||||
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then
|
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then
|
||||||
%do n=6 %to &ppkcnt;
|
%do n=6 %to &ppkcnt;
|
||||||
%let lev6=%scan(&posspks,&n);
|
%let lev6=%scan(&posspks,&n);
|
||||||
%if &lev1 ne &lev6 & &lev2 ne &lev6 & &lev3 ne &lev6
|
%if &lev1 ne &lev6 & &lev2 ne &lev6 & &lev3 ne &lev6
|
||||||
& &lev4 ne &lev6 & &lev5 ne &lev6 %then
|
& &lev4 ne &lev6 & &lev5 ne &lev6 %then
|
||||||
%do;
|
%do;
|
||||||
/* check for four level uniqueness */
|
/* check for four level uniqueness */
|
||||||
proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5 &lev6)
|
proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5 &lev6)
|
||||||
out=&tmpds noduprec;
|
out=&tmpds noduprec;
|
||||||
by _all_;
|
by _all_;
|
||||||
run;
|
run;
|
||||||
@@ -3213,7 +3213,7 @@ create table &outds (rename=(
|
|||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if &ppkcnt=6 %then %do;
|
%if &ppkcnt=6 %then %do;
|
||||||
%put &sysmacroname: No more PK guess possible;
|
%put &sysmacroname: No more PK guess possible;
|
||||||
%return;
|
%return;
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
@brief Guess the primary key of a table
|
@brief Guess the primary key of a table
|
||||||
@details Tries to guess the primary key of a table based on the following logic:
|
@details Tries to guess the primary key of a table based on the following logic:
|
||||||
|
|
||||||
* Columns with nulls are ignored
|
* Columns with nulls are ignored
|
||||||
* Return only column combinations that provide unique results
|
* Return only column combinations that provide unique results
|
||||||
* Start from one column, then move out to include composite keys of 2 to 6 columns
|
* Start from one column, then move out to include composite keys of 2 to 6 columns
|
||||||
|
|
||||||
The library of the target should be assigned before using this macro.
|
The library of the target should be assigned before using this macro.
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
/* get null count and row count */
|
/* get null count and row count */
|
||||||
%let tmpvar=%mf_getuniquename();
|
%let tmpvar=%mf_getuniquename();
|
||||||
proc sql noprint;
|
proc sql noprint;
|
||||||
create table _data_ as select
|
create table _data_ as select
|
||||||
count(*) as &tmpvar
|
count(*) as &tmpvar
|
||||||
%do i=1 %to &vcnt;
|
%do i=1 %to &vcnt;
|
||||||
%let var=%scan(&vars,&i);
|
%let var=%scan(&vars,&i);
|
||||||
@@ -85,10 +85,10 @@
|
|||||||
%put &sysmacroname: &baseds has no combination of unique records! Exiting.;
|
%put &sysmacroname: &baseds has no combination of unique records! Exiting.;
|
||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* now check cardinality */
|
/* now check cardinality */
|
||||||
proc sql noprint;
|
proc sql noprint;
|
||||||
create table _data_ as select
|
create table _data_ as select
|
||||||
%do i=1 %to &ppkcnt;
|
%do i=1 %to &ppkcnt;
|
||||||
%let var=%scan(&posspks,&i);
|
%let var=%scan(&posspks,&i);
|
||||||
count(distinct &var) as &var
|
count(distinct &var) as &var
|
||||||
@@ -212,7 +212,7 @@
|
|||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if &ppkcnt=4 %then %do;
|
%if &ppkcnt=4 %then %do;
|
||||||
%put &sysmacroname: No more PK guess possible;
|
%put &sysmacroname: No more PK guess possible;
|
||||||
%return;
|
%return;
|
||||||
@@ -228,7 +228,7 @@
|
|||||||
%let lev3=%scan(&posspks,&k);
|
%let lev3=%scan(&posspks,&k);
|
||||||
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
|
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
|
||||||
%let lev4=%scan(&posspks,&l);
|
%let lev4=%scan(&posspks,&l);
|
||||||
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
|
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
|
||||||
%do m=5 %to &ppkcnt;
|
%do m=5 %to &ppkcnt;
|
||||||
%let lev5=%scan(&posspks,&m);
|
%let lev5=%scan(&posspks,&m);
|
||||||
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %do;
|
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %do;
|
||||||
@@ -250,7 +250,7 @@
|
|||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if &ppkcnt=5 %then %do;
|
%if &ppkcnt=5 %then %do;
|
||||||
%put &sysmacroname: No more PK guess possible;
|
%put &sysmacroname: No more PK guess possible;
|
||||||
%return;
|
%return;
|
||||||
@@ -266,17 +266,17 @@
|
|||||||
%let lev3=%scan(&posspks,&k);
|
%let lev3=%scan(&posspks,&k);
|
||||||
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
|
%if &lev1 ne &lev3 and &lev2 ne &lev3 %then %do l=4 %to &ppkcnt;
|
||||||
%let lev4=%scan(&posspks,&l);
|
%let lev4=%scan(&posspks,&l);
|
||||||
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
|
%if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then
|
||||||
%do m=5 %to &ppkcnt;
|
%do m=5 %to &ppkcnt;
|
||||||
%let lev5=%scan(&posspks,&m);
|
%let lev5=%scan(&posspks,&m);
|
||||||
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then
|
%if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then
|
||||||
%do n=6 %to &ppkcnt;
|
%do n=6 %to &ppkcnt;
|
||||||
%let lev6=%scan(&posspks,&n);
|
%let lev6=%scan(&posspks,&n);
|
||||||
%if &lev1 ne &lev6 & &lev2 ne &lev6 & &lev3 ne &lev6
|
%if &lev1 ne &lev6 & &lev2 ne &lev6 & &lev3 ne &lev6
|
||||||
& &lev4 ne &lev6 & &lev5 ne &lev6 %then
|
& &lev4 ne &lev6 & &lev5 ne &lev6 %then
|
||||||
%do;
|
%do;
|
||||||
/* check for four level uniqueness */
|
/* check for four level uniqueness */
|
||||||
proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5 &lev6)
|
proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5 &lev6)
|
||||||
out=&tmpds noduprec;
|
out=&tmpds noduprec;
|
||||||
by _all_;
|
by _all_;
|
||||||
run;
|
run;
|
||||||
@@ -295,7 +295,7 @@
|
|||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if &ppkcnt=6 %then %do;
|
%if &ppkcnt=6 %then %do;
|
||||||
%put &sysmacroname: No more PK guess possible;
|
%put &sysmacroname: No more PK guess possible;
|
||||||
%return;
|
%return;
|
||||||
|
|||||||
Reference in New Issue
Block a user