BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
texasmfp
Lapis Lazuli | Level 10

A program I run frequently generates two ERROR messages.  Is there a way to have the message written to a variable and saved in a database?  Note that I am looking for the actual text of the ERROR message to be written to a variable.  For example:

 

ERROR: Incomplete JSON in input

 

I'd like to save the string "Incomplete JSON in input" as the value in a field, call it errorlog.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
texasmfp
Lapis Lazuli | Level 10

Kurt:  neither of those will work, but there is yet another system variable that appears to work:  &syslibrc appears to generate different values for the two errors.  Thanks

View solution in original post

4 REPLIES 4
texasmfp
Lapis Lazuli | Level 10

Thanks Kurt.  While that is a neat tidbit, it seems to only put the 2nd line of the 2-line error message.  For example, when I get the following error

 

ERROR: Incomplete JSON in input

ERROR: Error in the LIBNAME statement.

 

%put &syserrortext; only prints the 2nd of the two lines in the log

 

SYMBOLGEN: Macro variable SYSERRORTEXT resolves to Error in the LIBNAME statement.
Error in the LIBNAME statement.

 

Unfortunately, I am trying to distinguish between two different errors, but each has the same 2nd message.

 

ERROR: Incomplete JSON in input

ERROR: Error in the LIBNAME statement.

 

versus

 

ERROR: Physical file does not exist, e:\SAS Temporary Files\_TD10912_DESKTOP-575EP3T_\#LN01301.

ERROR: Error in the LIBNAME statement.

Kurt_Bremser
Super User

That will be a problem with steps causing more than one message, as the macro variable always displays the last message only.

 

I can only propose two workarounds:

  • check the automatic macro variables SYSCC and SYSERR to see which codes are set when your "target problem" arises. From these you can then possibly deduct the ERROR text.
  • if this has to be done for batch programs, check the log file after the program ends for the text and, if encountered, run a quick SAS program that adds the program name and message to a dataset. Basically, do a simple log file parsing.
texasmfp
Lapis Lazuli | Level 10

Kurt:  neither of those will work, but there is yet another system variable that appears to work:  &syslibrc appears to generate different values for the two errors.  Thanks

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 6012 views
  • 2 likes
  • 2 in conversation