Skip to content

PharmaForest/qc_cat_referee

Repository files navigation

qc_cat_referee

A SAS macro toolkit for automated data quality control. Applies integrity constraints to judge datasets (OK/NG) and outputs clear, visual QC results — with a cat referee making the call.

Image

%cat_rule_judgment() macro

Purpose: Apply a user-defined rule as a temporary integrity constraint (CHECK) on a dataset and judge whether the dataset satisfies the rule.

Parameters:

  lib=                Library name (default=WORK).
  ds=                 Dataset name (required).
  rule=               Rule expression to be checked (default: %nrstr(14 < AGE)).
  rule_no=            Rule number identifier. If omitted, &SYSINDEX is used.
  auto_delete_rule=   Y/N. If Y (default), the integrity constraint is deleted 
                      automatically after the check.

Process:

  1. Create a temporary integrity constraint on the dataset.
  2. Check if the rule can be successfully applied.
  3. Output judgment results (OK/NG) with icons and formatted print.
  4. Optionally delete the integrity constraint.
  5. Write results to the log for transparency.

Output:

  • A dataset named CAT_JUDGE_<rule_no> containing the judgment result.
  • ODS HTML/PRINT output with visual OK/NG.
  • NOTE messages in the SAS log.

Example:

data class;
   set sashelp.class;
run;
%cat_rule_judgment(lib=work,ds=class, rule=%nrstr(18>age and 50 <weight) )
Image
 %cat_rule_judgment(lib=work,ds=class, rule=%nrstr(18>age and 60 <weight) )
Image

%cat_unique_judgment() macro

Purpose: Apply a UNIQUE integrity constraint on one or more key variables in a dataset and judge whether the dataset satisfies uniqueness.

Parameters:

  lib=                Library name (default=WORK).
  ds=                 Dataset name (required).
  key=                Key variable(s) to be checked for uniqueness (default=NAME).
  rule_no=            Rule number identifier. If omitted, &SYSINDEX is used.
  auto_delete_rule=   Y/N. If Y (default), the integrity constraint is deleted 
                      automatically after the check.

Process:

  1. Create a temporary UNIQUE integrity constraint on the specified key(s).
  2. Check if the constraint is successfully applied.
  3. Output judgment results (OK/NG) with icons and formatted print.
  4. Optionally delete the integrity constraint.
  5. Write results to the SAS log for documentation.

Output:

  • A dataset named CAT_JUDGE_<rule_no> containing the uniqueness judgment result.
  • ODS HTML/PRINT output with visual OK/NG indicators.
  • NOTE messages in the SAS log for traceability.

Example:

 data class;
	set sashelp.class;
 run;
%cat_unique_judgment(lib=work,ds=class, key=age sex )
Image
%cat_unique_judgment(lib=work,ds=class, key=age height weight sex )
image

%cat_unique_not_missing_judgment() macro

Purpose: Apply a PRIMARY KEY integrity constraint on one or more key variables in a dataset and judge whether the dataset satisfies both uniqueness and non-missing requirements.

Parameters:

  lib=                Library name (default=WORK).
  ds=                 Dataset name (required).
  key=                Key variable(s) to be checked for uniqueness and non-missing 
                      (default=NAME).
  rule_no=            Rule number identifier. If omitted, &SYSINDEX is used.
  auto_delete_rule=   Y/N. If Y (default), the integrity constraint is deleted 
                      automatically after the check.

Process:

  1. Create a temporary PRIMARY KEY integrity constraint on the specified key(s).
    (PRIMARY KEY enforces both uniqueness and NOT NULL.)
  2. Check if the constraint is successfully applied.
  3. Output judgment results (OK/NG) with icons and formatted print.
  4. Optionally delete the integrity constraint.
  5. Write results to the SAS log for documentation.

Output:

  • A dataset named CAT_JUDGE_<rule_no> containing the judgment result.
  • ODS HTML/PRINT output with visual OK/NG indicators.
  • NOTE messages in the SAS log for traceability.

Example:

data class2;
set sashelp.class;
if _N_=2 then call missing(NAME);
run;

%cat_unique_not_missing_judgment(lib=work,ds=class2, key=name)
image

Notes on versions history

  • 0.1.0(08September2025): Initial version.

What is SAS Packages?

The package is built on top of SAS Packages Framework(SPF) developed by Bartosz Jablonski.

For more information about the framework, see SAS Packages Framework.

You can also find more SAS Packages (SASPacs) in the SAS Packages Archive(SASPAC).

How to use SAS Packages? (quick start)

1. Set-up SAS Packages Framework

First, create a directory for your packages and assign a packages fileref to it.

filename packages "\path\to\your\packages";

Secondly, enable the SAS Packages Framework. (If you don't have SAS Packages Framework installed, follow the instruction in SPF documentation to install SAS Packages Framework.)

%include packages(SPFinit.sas)

2. Install SAS package

Install SAS package you want to use with the SPF's %installPackage() macro.

  • For packages located in SAS Packages Archive(SASPAC) run:

    %installPackage(packageName)
  • For packages located in PharmaForest run:

    %installPackage(packageName, mirror=PharmaForest)
  • For packages located at some network location run:

    %installPackage(packageName, sourcePath=https://some/internet/location/for/packages)

    (e.g. %installPackage(ABC, sourcePath=https://github.com/SomeRepo/ABC/raw/main/))

3. Load SAS package

Load SAS package you want to use with the SPF's %loadPackage() macro.

%loadPackage(packageName)

Enjoy!

About

mirror of qc_cat_referee

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
license.sas

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages