BookmarkSubscribeRSS Feed
GeorgeSAS
Lapis Lazuli | Level 10

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;

 

11 REPLIES 11
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
GeorgeSAS
Lapis Lazuli | Level 10

thanks,

 

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

 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
GeorgeSAS
Lapis Lazuli | Level 10
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
PaigeMiller
Diamond | Level 26
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?

--
Paige Miller
GeorgeSAS
Lapis Lazuli | Level 10
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 .

Reeza
Super User

@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.

GeorgeSAS
Lapis Lazuli | Level 10
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.

ChrisNZ
Tourmaline | Level 20

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. 

GeorgeSAS
Lapis Lazuli | Level 10

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.

Quentin
Super User

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.
BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

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!

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
  • 2668 views
  • 1 like
  • 5 in conversation