BookmarkSubscribeRSS Feed
Mike_Davis
Fluorite | Level 6


Hello everyone,

When we run a long SAS code, errors maybe happen.and the error information would be push into SAS log.

My question is if  an error happened how we can stop running the rest program immediately and have the error information recorded in a macro variable for the future reference?

Thanks!

Mike

5 REPLIES 5
Mike_Davis
Fluorite | Level 6

%put &syserr;

Mike_Davis
Fluorite | Level 6

Does anyone has idea?

Thanks


ballardw
Super User

Once upon a time I did something similar. The general idea was to write a macro that would check the status after each datastep/ procedure boundary.

I would recommend that instead of saving to a macro variable alone to write it to a permanent dataset with some information.

There may be some operating system dependencies, so which OS? Also is this a batch job or interactive? Macros or running in a macro?

My approach had been that the macro was called at each boundary that provided some information as the last datastep/ proc in the program. Then the system date and time were queried.

If the %SYSERR was greater than a cutoff, 4 if I remember, then the the message was retrieved from the SYSERRORTEXT system variable. All of this was appended to a log dataset. Then used the %ABORT statement to end the program. Mine was batch job running overnight so I used the ABEND option.

RobertWoodruff
SAS Employee

Hi Mike,

Have you ever look at the SAS code gnerated by DI Studio? It uses macros to record the results of procs and data steps. Maybe that will help.

Between steps it generates code such as

%rcSet(&syserr);

%rcSet(&sqlrc);

Maybe this idea could be expanded for your needs.

Ksharp
Super User

"an error happened how we can stop running the rest program immediately "

Check some system options such as abend ...

"and have the error information recorded in a macro variable for the future reference?"

The &SYSERRORTEXT automatic macro variable contains the text of the last

error message formatted for display on the SAS log.

Ksharp

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1142 views
  • 0 likes
  • 4 in conversation