BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
amrshd
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
user24feb
Barite | Level 11

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;

View solution in original post

13 REPLIES 13
amrshd
Fluorite | Level 6

Shall I use syserr option to capture the type of error and map with the error codes?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

FreelanceReinh
Jade | Level 19

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.

user24feb
Barite | Level 11

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;
Ksharp
Super User

Why would you want do this ?

 

data x;
 set sashelp.class;
 error=_error_;
 run;
amrshd
Fluorite | Level 6

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_.

 

 

amrshd
Fluorite | Level 6
I want to do this because I have connected SAS with other application where user will not get to see the log, they can only see the outputs. So in case there are any errors they will get the conditional display of error message
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Kurt_Bremser
Super User

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.

amrshd
Fluorite | Level 6
Can I use &syserr option and capture what type of errors we are encountring??
Ksharp
Super User

Check function 

SYSMSG()

 

and system macro variables:

 %put &syswarningtext &syserrortext;
FreelanceReinh
Jade | Level 19

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 1951 views
  • 5 likes
  • 6 in conversation