DATA Step, Macro, Functions and more

alternative of ENDSAS

Reply
Regular Contributor
Posts: 241

alternative of ENDSAS

[ Edited ]

Hello all;

 

 

I run SAS on PC;

 

I want an alternative SAS code of 'ENDSAS' that will stop running the rest of SAS code without quit SAS session.

 

Please advise.

 

Thanks!

 

data a;
x=1;
run;

endsas;/* need something here without quiting SAS session*/

*don't want data b;
data b;
x=3;
run;

 

Trusted Advisor
Posts: 1,918

Re: alternative of ENDSAS

Posted in reply to GeorgeSAS

Look at the ABORT statement

 

ABORT CANCEL; seems to be what you want

 

but maybe one of the other options will work better for you.

Regular Contributor
Posts: 241

Re: alternative of ENDSAS

Posted in reply to PaigeMiller

thanks,

 

but :ERROR 180-322: Statement is not valid or it is used out of
proper order.

 

Trusted Advisor
Posts: 1,918

Re: alternative of ENDSAS

Posted in reply to GeorgeSAS

GeorgeSAS wrote:

thanks,

 

but :ERROR 180-322: Statement is not valid or it is used out of
proper order.

 


Perhaps you could show us the relevant portion of the SASLOG so we might be able to figure out what went wrong.

Regular Contributor
Posts: 241

Re: alternative of ENDSAS

Posted in reply to PaigeMiller
37 data a;
38 x=1;
39 run;

NOTE: The data set WORK.A has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds


40
41 abort;
-----
180

ERROR 180-322: Statement is not valid or it is used out of
proper order.

42
43 data b;
44 x=3;
45 run;

NOTE: The data set WORK.B has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
Trusted Advisor
Posts: 1,918

Re: alternative of ENDSAS

[ Edited ]
Posted in reply to GeorgeSAS
data a;
x=1;
abort cancel;
run;

But this is such a trivial example as to be meaningless.

 

Normally, you'd want to abort if some variable takes on a value that it shouldn't have, where you stop execution of the code if the variable has such a value, and you continue to execute the code when the variable takes on values that are allowed. There are examples in the documentation of using ABORT this way. Is that what you want?

Regular Contributor
Posts: 241

Re: alternative of ENDSAS

[ Edited ]
Posted in reply to GeorgeSAS
data a;
x=1;
run;

/*

data b;
x=3;
run;

this works but is a comment like method.

 

 

DOUBLE checked, this not work!!!

 

after /* if there are some macros or other comments /**/... some of the program code will still be executed.

 

put in bold,this will alert me that will cause error and almost it can't be recognized .

Super User
Posts: 19,815

Re: alternative of ENDSAS

Posted in reply to GeorgeSAS

@GeorgeSAS What are you trying to achieve here?

 

If something errors out, that the process stops or if you want the program to stop at a location, why have the rest of the code in the first place. I'm not understanding the business/process requirements here.

Regular Contributor
Posts: 241

Re: alternative of ENDSAS

[ Edited ]
DATA A;
X=1;
RUN;
%MACRO A;
DATA B;
X=2;
RUN;
%MEND;

In batch mode 'endsas' works well, but in PC  interactive mode,I know we can use macro.  

 

Thank you Reeza!

The reason I need this methods is I am working on developing stage,some code  I don't want them to be run currently but will run them in the future.

PROC Star
Posts: 1,760

Re: alternative of ENDSAS

Posted in reply to GeorgeSAS

That's an obvious gap in the SAS language, and an age-old request. 

 

See this page to vote for such a statement (but don't hold your breath) and to find a link to a workaround. 

Regular Contributor
Posts: 241

Re: alternative of ENDSAS

[ Edited ]

I think in most case base-SAS run in different platforms at the same time ,try not to create a new statement will reduce the confuse of people.

 

write a little bit more code(macro) will solve the problem. safely and confidently not mess/screw up the program.

PROC Star
Posts: 1,322

Re: alternative of ENDSAS

Posted in reply to GeorgeSAS

I'm confused.  What was wrong with the original solution of abort cancel?  In interactive SAS, I think it does just what you're looking for.  AFAIK, it's the "best" way to stop a submission in interactive SAS, without ending the SAS session.  It's even better than syntax check mode, since it prevents all code form being executed.

 

data a;
  x=1;
run;

/* need something here without quitting SAS session*/
data _null_;
  abort cancel;
run;

*don't want data b;
data b;
  x=3;
run;

Returns:

 

1    data a;
2      x=1;
3    run;

NOTE: The data set WORK.A has 1 observations and 1 variables.

4
5    /* need something here without quiting SAS session*/
6    data _null_;
7      abort cancel;
8    run;

ERROR: Execution terminated by an ABORT CANCEL statement at line 7 column 3.
_ERROR_=1 _N_=1
NOTE: The SAS System stopped processing due to receiving a CANCEL request.
Ask a Question
Discussion stats
  • 11 replies
  • 289 views
  • 1 like
  • 5 in conversation