SAS: Constraint Messages
SAS allows you to create custom messages when a constraint occurs. There are two options for a constraint:
- MESSAGE=: This is a custom message up to 250 characters.
- MSGTYPE=: This has two options. NEWLINE means that it is displayed in addition to the original error message. USER means that only the custom message is displayed.
Here’s a couple of examples that should make it clear.
proc sql UNDO_POLICY=REQUIRED; CREATE TABLE work.myjunk ( number int, number1 int CHECK (number < 5) Message='***This is my error***' Msgtype=USER ); INSERT INTO work.myjunk VALUES (6,6); SELECT * FROM work.myjunk; quit; ERROR: ***This is my error*** NOTE: This insert failed while attempting to add data from VALUES clause 1 to the data set. proc sql UNDO_POLICY=REQUIRED; CREATE TABLE work.myjunk ( number int, number1 int CHECK (number < 5) Message='***This is my error***' Msgtype=NEWLINE ); INSERT INTO work.myjunk VALUES (6,6); SELECT * FROM work.myjunk; quit;
ERROR: ***This is my error*** Add/Update failed for data set WORK.MYJUNK because data value(s) do not comply with integrity
constraint _CK0001_.
NEWLINE is the default option.