BookmarkSubscribeRSS Feed
acordes
Rhodochrosite | Level 12

I'm struggling to understand how to use correctly the abort statement. 

The context is the following: I have a job and prompt combo which I run from SAS Studio. It works fine except the fact that the sas program starts executing again when you go to the sas code tab again, the preview sheet. 

I want to avoid this by using a abort statement based on the existence of the macro variables that come from the user prompts. 

In the code I'd like to delete this macro variables and put the abort condition at the start of the sas code. I don't attach the real code but the code where I try to approach this funcionality. 

What I want to achieve is that the code stops restarting if the macro variables (fed by the prompt) do not exist. To guarantee this I want to delete them at the end of the code. 

 

 

the prompt formthe prompt formthe resulting window after submitthe resulting window after submitrestart of the code execution (without calliing the form?) when coming back to the windowrestart of the code execution (without calliing the form?) when coming back to the window

%let test=arne;
%let test2=nadine;

%put &test &test2;


%SYMDEL test;

%put &test &test2;

data _null_;
if %symexist(test2) then alarm="exists";
put alarm=;
run;

%macro test;
data _null_;
if %symexist(test) then %abort cancel;
put alarm=;
run;

proc freq data=sashelp.cars;
table make;
run;

%mend;

%test;

 

 

11 REPLIES 11
sbxkoenk
SAS Super FREQ

Hello,

 

Any chance you can use the below example?

 

Scroll down on this page :
SAS 9.4 / Viya 3.5
Macro Language Reference
%GOTO Macro Statement

https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0jfeh75p72icen1ddd9una5zbmm.htm

to :

Example: Providing Exits in a Large Macro

 

Good luck,

Koen

acordes
Rhodochrosite | Level 12

Hi Koen,

the %goto statement works in my example, now I have the challenge to wrap all the code into a macro block to be able to use it. 

 

%let test=arne;
%let test2=nadine;

%put &test &test2;


%SYMDEL test;

%put &test &test2;

data _null_;
if %symexist(test2) then alarm="exists";
put alarm=;
run;

%macro help;
data _null_;
%if  %symexist(test) %then %goto exit;
put alarm=;
run;

proc freq data=sashelp.cars;
table make;
run;

%exit: %mend;

%help;
sbxkoenk
SAS Super FREQ

OK. Nice!

Let the communities know if you encounter any obstacles in wrapping everything in a macro.
Maybe some of us are able to help you out in that case.

Koen

acordes
Rhodochrosite | Level 12

Thank you, I'm getting closer, but the endsas is a too restrictive option for me. It ends the session. 

I'm looking for the option that ends the sas code when entering the call execute. 

 

%let test=arne;
%let test2=nadine;

%put &test &test2;


%SYMDEL test;

%put &test &test2;

data _null_;
   if 1=1 then call execute('endsas;');
   stop;
run;

data _null_;
if %symexist(test2) then alarm="exists";
put alarm=;
run;

%macro help;
data _null_;
%if not %symexist(test) %then %goto exit;
put alarm=;
run;

proc freq data=sashelp.cars;
table make;
run;

%exit: %mend;

%help;

proc freq data=sashelp.cars;
table make;
run;

sbxkoenk
SAS Super FREQ

Hello,

 

when you 

%goto exit;

, you end the SAS code, no?
If you do not do anything after the macro call, your code stops running (as there's nothing left to run).

No need for "endsas;" statement / command.

 

Koen

ChrisNZ
Tourmaline | Level 20

@sbxkoenk The proc freq still runs.

 

This has been a request ever since I started using SAS, which is well into the last century. See https://communities.sas.com/t5/SASware-Ballot-Ideas/Create-new-statement-STOPROGRAMRIGHTHERE-or-simi...

AllanBowe
Barite | Level 11

Within the SASjs framework we constantly have a need for conditional aborts.  So, we wrote a macro for it:  https://core.sasjs.io/mp__abort_8sas.html

 

Example usage:

 

  %mp_abort(iftrue=(&somecondition=1)
    ,mac=&sysmacroname
    ,msg=%str(Some Condition Failed)
  )

 

/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
ChrisNZ
Tourmaline | Level 20

This still kills the SAS session right?

 

Very nice macro library, congrats! 🙂

AllanBowe
Barite | Level 11

It kills the session in all cases except for Stored Process sessions - as we found that this could leave orphan multibridge sessions and kill the server for some SAS 9 environments.

 

In this case, we take a unique approach - we open a macro but don't close it!  This means the rest of the code does not get executed (and the STP session ends "normally")

Something like this:

 

      filename skip temp;
      data _null_;
        file skip;
        put '%macro skip();';
        comment '%mend skip; -> fix lint ';
        put '%macro skippy();';
        comment '%mend skippy; -> fix lint ';
      run;
      %inc skip;
/Allan
SAS Challenges - SASensei
MacroCore library for app developers
SAS networking events (BeLux, Germany, UK&I)

Data Workflows, Data Contracts, Data Lineage, Drag & drop excel EUCs to SAS 9 & Viya - Data Controller
DevOps and AppDev on SAS 9 / Viya / Base SAS - SASjs
sbxkoenk
SAS Super FREQ

@AllanBowe wrote:

..., we take a unique approach - we open a macro but don't close it!  This means the rest of the code does not get executed (and the STP session ends "normally")

Interesting. I have never used that "trick". Something to remember. 🤔

Koen

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 11 replies
  • 830 views
  • 9 likes
  • 5 in conversation