BookmarkSubscribeRSS Feed
moseland
Fluorite | Level 6

As a new SAS user, I frequently make mistakes. I am confused on the syntax and usage of the STOP and ABORT functions to halt the progress of the code. When one wants to stop their code from running, do I need to always include these statements at the end of my program just in case? 

4 REPLIES 4
Tom
Super User Tom
Super User

If you are just learning to use SAS then you probably have no need for either of these statements.

s_lassen
Meteorite | Level 14

The STOP statement stops execution of a datastep, not a program, e.g.:

 

data _null_;
  set data1;
  call symputx('exec_date',exec_date);
  stop;
run;
  

In this example, the datastep stops immediately after executing SYMPUTX, so only one observation is read from DATA1. But all the program statements following the data step are executed as normal.

 

The ABORT statement is used to cancel execution of a program. So, if I had put an ABORT statement instead of STOP in the datastep, the code after the data step would not had been executed either (and your session may have ended, depending on what options you had used for the ABORT statement).

 

But as @Tom wrote: If you are just beginning to learn SAS, you probably have need of any of these statements.

ballardw
Super User

For what it may be worth, I haven't actually used an ABORT statement since 1996, which was the last SAS related job I had that did batch related processing.

 

I may have needed to use STOP as recently as 2008.

 

YMMV.

s_lassen
Meteorite | Level 14

I use both statements quite often (several times a year ;)).

 

The ABORT statement is also quite usable in online processing, where I most often use the ABORT CANCEL FILE version, which just stops execution of the currently submitted program, or the currently %INCLUDE-file.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1368 views
  • 3 likes
  • 4 in conversation