I've got a process were I append records to a dataset with a uniqe index.
This throws a warning - per design - about rejected records due to duplicate keys.
I want to capture this warning and put it in an email.
The email part is working fine but I have got issues getting the correct warning text.
Program:
proc append base=appdata.trigger data=trigger(where=(not missing(id))) force;
run;
%let warn=%superq(syswarningtext);
%put &warn;
Log:
9948 proc append base=appdata.trigger data=trigger(where=(not missing(contact_wid))) force;
9949 run;
NOTE: Appending WORK.TRIGGER to APPDATA.TRIGGER.
WARNING: Duplicate values not allowed on index hash_cd for file TRIGGER, 1620 observations rejected.
NOTE: There were 1620 observations read from the data set WORK.TRIGGER.
WHERE not MISSING(contact_wid);
NOTE: 0 observations added.
NOTE: The data set APPDATA.TRIGGER has 1659 observations and 5 variables.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.06 seconds
cpu time 0.07 seconds
9950 %put "&SYSWARNINGTEXT";
ERROR: Expected open parenthesis after macro function name not found.
" The argument to macro function not defined as a system variable"
I have had several different messages in the syswarningtext output EXCEPT the warning from the proc append.
any suggestions on how to get the correct warning text ?
-Karsten
PS: we're running 9.2
the lines you show for program and what you show for log do not match
specifically line 9950 and the PROC APPEND where data set option is not the same but I don't think that is the issue.
Maybe a problem with SYSFUNC somewhere in the 9947 lines above. I would start at the top and work my way down;
Might be interesting to see %PUT _AUTOMATIC_; before and after PROC APPEND no quoting require for _AUTOMATIC_;
SYSWARNINGTEXT is not reset to null when a proc completes successfully. So the error could be from an earlier step.
So I did the %put _AUTOMATIC_ before and after :
%put _automatic_;
proc append base=appdata.trigger data=trigger(where=(not missing(contact_wid))) force;
run;
%let warn=%superq(syswarningtext);
%put &warn;
%put _automatic_;
And this is what I got fromt that:
9967 %put _automatic_;
....
AUTOMATIC SYSWARNINGTEXT The argument to macro function %SYSGET is not defined as a system variable
9960
9961 proc append base=appdata.trigger data=trigger(where=(not missing(contact_wid))) force;
9962 run;
NOTE: Appending WORK.TRIGGER to APPDATA.TRIGGER.
WARNING: Duplicate values not allowed on index hash_cd for file TRIGGER, 1620 observations rejected.
NOTE: There were 1620 observations read from the data set WORK.TRIGGER.
WHERE not MISSING(contact_wid); NOTE: 0 observations added.
NOTE: The data set APPDATA.TRIGGER has 1659 observations and 5 variables.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.04 seconds
cpu time 0.05 seconds
9963
9964 %let warn=%superq(syswarningtext);
9965 %put &warn;
The argument to macro function %SYSGET is not defined as a system variable
9966
9967 %put _automatic_;
....
AUTOMATIC SYSWARNINGTEXT The argument to macro function %SYSGET is not defined as a system variable
So NO cange to SYSWARNINGTEXT at all
This is very interesting. I've tested this on my EG/UNIX SAS 9.3 and PROC APPEND does not update SYSWARNINGTEXT and the WARNING in the log does not even have the warning text color.
You can roll you own append and take control of the results of _IORC_ get the desired result my example is very simple but you get the idea.
Interesting indeed. Also run on 9.3 EG/UNIX, below shows PROC APPEND does write the warning to the log in color and updates &SYSWARNINGTEXT when the warning is about mismatch variables. Same resuls on 9.3 on Win 7.
But indeed, using DN's sample data a PROC APPEND that violates a unique index generates a warning that is NOT colored (can't remember seeing that before), and does not update &SYSWARNINGTEXT. Makes one curious about how these warnings are being "caught" within SAS's inner workings. Seems this one fell through a hole somehow. Apparently the coloring rule is not as simple as "if the line being written to the log starts with WARNING: ...."
data a; x=1; run; data b; run; proc append base=a data=b; run; %put &syswarningtext;
one distinction between the two warnings in this log
92 data a( index=(x/unique));
93 x=1;
94 run;
NOTE: The data set WORK.A has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
95 data b;
96 run;
NOTE: The data set WORK.B has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
97 proc append base=a data=b;
98 run;
NOTE: Appending WORK.B to WORK.A.
WARNING: Variable x was not found on DATA file.
NOTE: There were 1 observations read from the data set WORK.B.
NOTE: 1 observations added.
NOTE: The data set WORK.A has 2 observations and 1 variables.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
99 %put &syswarningtext;
Variable x was not found on DATA file.
100
101 data b;
102 x=2;
103 output; output;
104 run;
NOTE: The data set WORK.B has 2 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
105 proc append base=a data=b;
106 run;
NOTE: Appending WORK.B to WORK.A.
WARNING: Duplicate values not allowed on index x for file A, 1 observations rejected.
NOTE: There were 2 observations read from the data set WORK.B.
NOTE: 1 observations added.
NOTE: The data set WORK.A has 3 observations and 1 variables.
NOTE: PROCEDURE APPEND used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
107 %put &syswarningtext;
Variable x was not found on DATA file.
The warning which fills the automatic SYSWARNINGTEXT is a compile-time message and the other is a run-time message.
I expect they must be handled differently.
What handling would you want for multiple run-time warning messages?
Would you want
: all of these to fill the SYSWARNINGTEXT
, just the last
or just the first?
Hi Peter,
For run-time warning messages, I think I would want just the last in SYSWARNINGTEXT, and I would definitely want it colored in the log.
In a DATA step, run-time warning messages are colored, and do populate SYSWARNINGTEXT, even if they are user-written:
35 data _null_; 36 if 1 then put "WARNING: something bad happened"; 37 if 1 then put "WARNING: something really bad happened"; 38 run; WARNING: something bad happened WARNING: something really bad happened 39 40 %put &syswarningtext; something really bad happened
so it looks like the APPEND msg handling in the log should be referred to tech support.
Thank you all for your contributions.
I will make sure to make Tech support aware of this.
I ended up not using SYSWARNINGTEXT and instead create my own counts at the end of the program.
-Karsten
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.