Reputation: 3
I have to do a condition in SAS Guide if the SYSERRORTEXT is blank or not, but the code that I created is giving me only the value 0, indicating that the code is not good, even I received the e-mail. I've tried everything for days, but anything is working. I've tried IS MISSING, IS NULL, " ", LIKE something etc. I've tried the variable SYSERR too, prxmatch('/ERROR\d+/', text) > 0, anything, but it's getting me crazy. How can I get the best code of it? Thank you very much!
%let emails = "[email protected]";
filename msg email
to=(&emails)
from="[email protected]"
subject="yurusg"
type="text/html"
attach=('C:\\Temp\\RESULT_VALID_DT_REF_BO.xlsx')
;
ods html file=msg rs=none;
proc odstext;
p " ";
p "Olá, ";
p " ";
p "Segue em anexo o resultado da validação da DT_REFERENCIA_BO nas entidades CONTRATO e CONTA. ";
p " ";
p "Obrigada. ";
run;
ods html close;
%END;
/\* Check if there was an error \*/
%put &SYSERRORTEXT ;
data Var_tab;
FORMAT varerror best8.;
proc sql ;
SELECT CASE WHEN "&SYSERRORTEXT" = "" THEN varerror = 1 ELSE varerror = 0 END AS VAR8
into :varerror
from WORK.Var_tab ;quit;
I want a variable telling me if the SYSERRORTEXT is blank or not.
Upvotes: 0
Views: 111
Reputation: 51566
The SYSERRORTEXT macro variable is readonly. The only way to change it is to generate an ERROR message. See https://communities.sas.com/t5/SAS-Programming/syserrortext-macro-variable/td-p/188721#:~:text=Automatic%20macro%20variable%20SYSERRORTEXT%20is,the%20last%20ERROR%3A%20line%20logged.
Because of that you might what to use your own user created macro variable instead. Let's call it USERERRORTEXT just to have something to use in an example. So when you detect there has been an error immediately save SYSERRORTEXT to USERERRORTEXT and then reset SYSERRORTEXT so that you can later check it.
So before your step that you want to capture the error message make sure it is cleared.
%put NOTE: This ERROR message is used to clear the SYSERRORTEXT macro variable.;
%put ERROR: %str( );
Then immediately after the step that might generate an error add code like:
%let usererrortext=%qsysfunc(trimn(%superq(syserrortext)));
%let varerror=0;
%if &usererrortext ne %then %do;
%put NOTE: This ERROR message is used to clear the SYSERRORTEXT macro variable.;
%put ERROR: %str( );
%put varerror=1;
%end;
Then in your code test the value of VARERROR and store the value of USERERRORTEXT.
Upvotes: 0
Reputation: 2776
I think you want:
proc sql ;
SELECT CASE WHEN "%superq(SYSERRORTEXT)" = "" THEN 1 ELSE 0 END into :varerror
from WORK.Var_tab ;
quit;
In your original code inside the CASE WHEN
clause, varerror = 1
is a logical expression which equals 1 if varerror is 1 and equals 0 otherwise. varerror = 0
is a logical expression which equals 1 if varerror is 0 and equals 0 otherwise. Because varerror
is missing, neither of the conditions is true so the result is 0.
The %superq()
is included in case &SYSERRORTEXT
contains double quotes.
Upvotes: 0
Reputation: 26
I think you would be better off using SYSCC instead of SYSERRORTEXT.
8 %let syscc=0;
49 %put NOTE: &=syscc &=syserrortext;
NOTE: SYSCC=0 SYSERRORTEXT=
50
51 bad;
___
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
52 %put NOTE: &=syscc &=syserrortext;
NOTE: SYSCC=3000 SYSERRORTEXT=180-322: Statement is not valid or it is used out of proper order.
53
54 %if &syscc GT 0 %then %do;
55 %let flag=1;
56 %end;
57 %else %do;
58 %let flag=0;
59 %end;
60
61 %put NOTE: &=flag;
NOTE: FLAG=1
Upvotes: 0