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.
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:
- Create a temporary integrity constraint on the dataset.
- Check if the rule can be successfully applied.
- Output judgment results (OK/NG) with icons and formatted print.
- Optionally delete the integrity constraint.
- 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) )
%cat_rule_judgment(lib=work,ds=class, rule=%nrstr(18>age and 60 <weight) )
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:
- Create a temporary UNIQUE integrity constraint on the specified key(s).
- Check if the constraint is successfully applied.
- Output judgment results (OK/NG) with icons and formatted print.
- Optionally delete the integrity constraint.
- 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 )
%cat_unique_judgment(lib=work,ds=class, key=age height weight sex )
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:
- Create a temporary PRIMARY KEY integrity constraint on the specified key(s).
(PRIMARY KEY enforces both uniqueness and NOT NULL.) - Check if the constraint is successfully applied.
- Output judgment results (OK/NG) with icons and formatted print.
- Optionally delete the integrity constraint.
- 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)
- 0.1.0(08September2025): Initial version.
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).
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)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/))
Load SAS package you want to use with the SPF's %loadPackage() macro.
%loadPackage(packageName)