DATA Step, Macro, Functions and more

Always auto run macro after submitting a sas code

Reply
Frequent Contributor
Posts: 92

Always auto run macro after submitting a sas code

I have a macro %ERR that checks for error and play a sound. I want this macro to run it every time when I execute a code. Instead of manually running %ERR, is there anywhere to setup in Preferences so that it automatically runs?

There is a similar feature in Tools > Options > Preferences > Results for HTML Output which is very useful.

Super User
Super User
Posts: 7,035

Re: Always auto run macro after submitting a sas code

Not sure what you mean.  Are you running programs interactively from the SAS Display Manager?  Then you can issue any commands you want and even define keys to execute the commands for you. You can even add icons to run the commands.  For example you could define the F8 key to be the command sequence submit followed by the gsub command to submit the call to your %ERR macro. You can also define command macros that instead of generating SAS program statements can be used to generate Display Manager commands like submit or gsub.

Super User
Posts: 10,018

Re: Always auto run macro after submitting a sas code

Yes. SAS offer a system option to solve such problem. You can populate the statements of the macro into this option . and these statements will execute after the code running.

TERMSTMT= System Option

Specifies the SAS statements to execute when SAS terminates.

Valid in: configuration file, SAS invocation

Category: Environment control: Initialization and operation

PROC OPTIONS GROUP= EXECMODES

Syntax

TERMSTMT=’statement(s)’

Syntax Description

’statement(s)’

is one or more SAS statements.

Maximum length: 2,048 characters

Operating Environment Information: In some operating system environments there is

a limit to the size of the value for TERMSTMT=. To circumvent this limitation, you can

use the %INCLUDE statement.  

Details

TERMSTMT= is fully supported in batch mode. In interactive modes, TERMSTMT= is

executed only when you submit the ENDSAS statement from an editor window to

terminate the SAS session. Terminating SAS by any other means in interactive mode

results in TERMSTMT= not being executed.

An alternate method for specifying TERMSTMT= is to put a %INCLUDE statement

at the end of a batch file or to submit a %INCLUDE statement before terminating the

SAS session in interactive mode.

Comparisons

TERMSTMT= specifies the SAS statements to be executed at SAS termination, and

INITSTMT= specifies the SAS statements to be executed at SAS initialization.

Ksharp

Frequent Contributor
Posts: 92

Re: Always auto run macro after submitting a sas code

TERMSTMT= is fully supported in batch mode. In interactive modes, TERMSTMT= is executed only when you submit the ENDSAS statement from an editor window to terminate the SAS session. Terminating SAS by any other means in interactive mode results in TERMSTMT= not being executed.


I am using SAS Display Manager. I want it to play a loud sound when it hits a error. TERMSTMT can be used in SAS invocation which is good. But it seems it only executes when SAS terminates. (ENDSAS will close SAS session which I do not want)



I am exploring all the solutions suggested in this thread. Thanks.

Super User
Posts: 11,336

Re: Always auto run macro after submitting a sas code

Here's a warped approach. Redefine your macro as

%macro Run;

run;

<code from your ERR macro here>

%mend;

Then any proc or data step you want end with %run; instead of a simple run; statement.

If the issue is getting tired of typing the macro into the code then create an editor macro to insert the statement.

Tom's approach is probably better though.

Occasional Contributor
Posts: 6

Re: Always auto run macro after submitting a sas code

I would like to see your error checking code if you're prepared to share?  I've long been trying to write something which determines whether an error occurs and can decide whether to submit further statements or not.

PROC Star
Posts: 1,759

Re: Always auto run macro after submitting a sas code

Maybe this would help you cancel further statements in case of errors David:

http://support.sas.com/kb/24/825.html

Frequent Contributor
Posts: 92

Re: Always auto run macro after submitting a sas code

I am still exploring. I am not running a batch jobs. I am using SAS Display Manager interactive. Sometimes, I am tired to trying to read the long logs, I want it to play a loud sound.

Error Checking Macro will be based on this paper, but instead of emailing me, it will play a sound.

http://www.nesug.org/proceedings/nesug05/ap/ap9.pdf

Occasional Contributor
Posts: 14

Re: Always auto run macro after submitting a sas code

Hi..Hellind

Did you find any solution for this.? Am searching for same kind of solution..

Thanks,

Kishore Vengala

Respected Advisor
Posts: 3,799

Re: Always auto run macro after submitting a sas code

Posted in reply to kishore415

You can do that with SAS Enterprise Guide.  See: Tool>Options>SAS Programs.

Ask a Question
Discussion stats
  • 9 replies
  • 784 views
  • 0 likes
  • 8 in conversation