I want to store the value of _ERROR_ in a SAS dataset. I have a complete program written, so in case my complete code is not working I need a SAS dataset to be created which will have have value of ERROR = 0 in case there are no errors and ERROR = 1 when there are errors in the program.
Thanks
I believe that you are trying to access the log (?)
Proc PrintTo Log="D:\xxx.LOG" New; Run;
Data _NULL_;
x=IntNX('month',2,'01JAN2016'); * d missing;
Run;
Proc PrintTo; Run;
Data Errors (Drop=Line);
Infile "D:\xxx.LOG" Delimiter='09'x Missover End=Eof;
Informat Line $200.;
Input Line;
Retain MyError 0;
If Find(UpCase(Line),'_ERROR_=1') Then MyError=1;
If Eof Then Output;
Run;
Have you already taken a look at the automatic macro variable SYSCC? It might provide what you need.
Shall I use syserr option to capture the type of error and map with the error codes?
Why do you want to do this? The log is the record of a programs run, most people I know scan the log for findings as error codes may not capture everything. So my suggestion is use the log, don't try to re-invent it. The auto error macro variables are useful really only in deciding wether to continue a program or branch somewhere else.
Very true, @RW9. There is a lot that can go wrong in a program without SYSCC being set to a value >0, including cases where _ERROR_ was set to 1 (not to speak of logical errors).
Example (log):
1 data _null_; 2 a=min(1/max(input('x',1.)+1,0),11); 3 put a 1. b; 4 run; NOTE: Variable b is uninitialized. NOTE: Invalid argument to function INPUT at line 2 column 13. NOTE: Division by zero detected at line 2 column 8. *. a=11 b=. _ERROR_=1 _N_=1 NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 2:26 NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 2:8 1 at 2:13 NOTE: At least one W.D format was too small for the number to be printed. The decimal may be shifted by the "BEST" format. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 5 %put &syscc; 0
That said, SYSCC has at least a chance to provide minimal status information about "a complete program," whereas _ERROR_ doesn't.
I believe that you are trying to access the log (?)
Proc PrintTo Log="D:\xxx.LOG" New; Run;
Data _NULL_;
x=IntNX('month',2,'01JAN2016'); * d missing;
Run;
Proc PrintTo; Run;
Data Errors (Drop=Line);
Infile "D:\xxx.LOG" Delimiter='09'x Missover End=Eof;
Informat Line $200.;
Input Line;
Retain MyError 0;
If Find(UpCase(Line),'_ERROR_=1') Then MyError=1;
If Eof Then Output;
Run;
Why would you want do this ?
data x;
set sashelp.class;
error=_error_;
run;
Thanks for the reply.
This will not work as I do not want value of _ERROR_ in a dataset. If there are any errors throughout the program (any kind of errors) a new dataset should be created which will have a value of _ERROR_.
Why can they not see the log? It is a text file which can be saved anywhere. Use the proc printto, and then either goto the file directly, or send it over as an output file.
The other issue with storing codes is that you end up in a loop. You have code to capture the code, but what if that has an error, will you capture the code for that, and then the code there...
Far easier just to use the log.
It is quite easy to make the logs visible via web browser. Our logs from all the batch jobs are made available for all data warehouse users in this way.
Check function
SYSMSG()
and system macro variables:
%put &syswarningtext &syserrortext;
I could imagine that the users of the "application" that @amrshd has "connected SAS with" aren't SAS programmers, but just users of an end-user application. They are not supposed and don't want to look behind the scenes of their GUI and would be unable to interpret the log.
So, I think the best way to inform them adequately about the status of their application would be to scan the SAS log and to include various checking steps (e.g. for data issues) in the program and boil down the results to a user-friendly status message in non-technical English (or whatever the most appropriate language is) which is eventually displayed on the GUI.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.