Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mp_guesspk.sas File Reference

Guess the primary key of a table. More...

Go to the source code of this file.

Detailed Description

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

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";
%inc mc;
%mp_guesspk(sashelp.class,outds=classpks)
Parameters
basedsThe dataset to analyse
outds=The output dataset to contain the possible PKs
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.
min_rows=The minimum number of rows a table should have in order to try and guess the PK. Default=5.

Dependencies

Version
9.3
Author
Allan Bowe

Definition in file mp_guesspk.sas.