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

Extract the primary key fields from a table or library. More...

Go to the source code of this file.

Detailed Description

Examines the constraints to identify primary key fields - indicated by an explicit PK constraint, or a unique index that is also NOT NULL.

Can be executed at both table and library level. Supports both BASE engine libraries and SQL Server.

Usage:

proc sql;
create table work.example(
  TX_FROM float format=datetime19.,
  DD_TYPE char(16),
  DD_SOURCE char(2048),
  DD_SHORTDESC char(256),
  constraint pk primary key(tx_from, dd_type,dd_source),
  constraint unq unique(tx_from, dd_type),
  constraint nnn not null(DD_SHORTDESC)
);
%mp_getpk(work,ds=example)

Returns:

libref:$8. dsn:$32. memtype:$8. dbms_memtype:$32. typemem:$8. memlabel:$256. nvar:best. compress:$8. pk_fields:$512.
WORK EXAMPLE DATA DATA 4 NO TX_FROM DD_TYPE DD_SOURCE
Parameters
[in]libThe libref to examine
[in]ds=(0) Select the dataset to examine, else use 0 for all tables
[in]mdebug=(0) Set to 1 to preserve temp tables, print var values etc
[out]outds=(work.mp_getpk) The name of the output table to create.

SAS Macros

Related Macros

Version
9.3
Author
Macro People Ltd

Definition in file mp_getpk.sas.