diff --git a/README.md b/README.md index ac4b5a0..3e50671 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Macro Core [![npm package][npm-image]][npm-url] [![Github Workflow][githubworkflow-image]][githubworkflow-url] -[![npm](https://img.shields.io/npm/dt/@sasjs/core)]() +![npm](https://img.shields.io/npm/dt/@sasjs/core) ![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/@sasjs/core) [![License](https://img.shields.io/apm/l/atomic-design-ui.svg)](/LICENSE) ![GitHub top language](https://img.shields.io/github/languages/top/sasjs/core) diff --git a/base/mp_getpk.sas b/base/mp_getpk.sas index 0583058..1bf4e38 100644 --- a/base/mp_getpk.sas +++ b/base/mp_getpk.sas @@ -37,6 +37,7 @@

Related Macros

@li mp_getpk.test.sas + @li mp_guesspk.sas @version 9.3 @author Macro People Ltd diff --git a/base/mp_guesspk.sas b/base/mp_guesspk.sas index a8b9200..2ef1049 100644 --- a/base/mp_guesspk.sas +++ b/base/mp_guesspk.sas @@ -1,32 +1,37 @@ /** - @file mp_guesspk.sas + @file @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 * 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 composite keys of 2 to 6 columns The library of the target should be assigned before using this macro. Usage: - filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas"; + filename mc url + "https://raw.githubusercontent.com/sasjs/core/main/all.sas"; %inc mc; %mp_guesspk(sashelp.class,outds=classpks) @param baseds The dataset to analyse @param outds= The output dataset to contain the possible PKs - @param max_guesses= The total number of possible primary keys to generate. A - table is likely to have multiple unlikely PKs, so no need to list them all. Default=3. - @param min_rows= The minimum number of rows a table should have in order to try - and guess the PK. Default=5. + @param max_guesses= (3) The total number of possible primary keys to generate. + A table may have multiple unlikely PKs, so no need to list them all. + @param min_rows= (5) The minimum number of rows a table should have in order + to try and guess the PK.

SAS Macros

@li mf_getvarlist.sas @li mf_getuniquename.sas @li mf_nobs.sas +

Related Macros

+ @li mp_getpk.sas + @version 9.3 @author Allan Bowe @@ -196,7 +201,8 @@ %let lev4=%scan(&posspks,&l); %if &lev1 ne &lev4 and &lev2 ne &lev4 and &lev3 ne &lev4 %then %do; /* check for four level uniqueness */ - proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4) out=&tmpds noduprec; + proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4) + out=&tmpds noduprec; by _all_; run; %if %mf_nobs(&tmpds)=&rows %then %do; @@ -233,7 +239,8 @@ %let lev5=%scan(&posspks,&m); %if &lev1 ne &lev5 & &lev2 ne &lev5 & &lev3 ne &lev5 & &lev4 ne &lev5 %then %do; /* check for four level uniqueness */ - proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5) out=&tmpds noduprec; + proc sort data=&pkds(keep=&lev1 &lev2 &lev3 &lev4 &lev5) + out=&tmpds noduprec; by _all_; run; %if %mf_nobs(&tmpds)=&rows %then %do; @@ -282,7 +289,8 @@ run; %if %mf_nobs(&tmpds)=&rows %then %do; proc sql; - insert into &outds values("&lev1 &lev2 &lev3 &lev4 &lev5 &lev6"); + insert into &outds + values("&lev1 &lev2 &lev3 &lev4 &lev5 &lev6"); %if %mf_nobs(&outds) ge &max_guesses %then %do; %put &sysmacroname: Max PKs reached at Level 6 for &baseds; %return;