Hi all,
I've been playing a bit with the endsas statement, which according to the SAS documentation (https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsglobal/p1aok1r21bw4oqn17duao6d81m2l.ht... [without arguments] "terminates a SAS session as soon as it is encountered in a DATA step or a PROC step. ENDSAS terminates the entire SAS session and not just the SAS job.".
If I type endsas in a SAS windowing environment the application exits, but if I use endsas as part of the precode to a transformation in a SAS job in SAS DI Studio, the job stops but DI Studio remains active.
Based on the documentation, I actually expected DI Studio to close (as is the case with the SAS windowing environment). Am I missing something?
TIA
Anne.
DI Studio works in a bit diffrent way than Base SAS windowing environment. DI Studio is a Java application, and when using the main windows, wizards etc it interacts with the Metadata Server.
When you execute your jobs in DI Studio, you create a server side SAS session through a mechanism called Workspace Server. This SAS session will terminate when it encounters the ENDSAS statement. The DI Studio interface is not dependant on the status of your submitted SAS code.
DI Studio is a developer tool, not a tool for production execution of code.
In general, you should not use the ENDSAS statement when you are running SAS from any interface: SAS Studio, DI Studio, Visual Analytics, etc. The ENDSAS statement is used in command-line mode (a console window) to terminate a SAS session and return control to the shell.
While ENDSAS was originally designed to be used in command-line mode, it is perfectly fine to use it in any SAS interface, but it is especially useful in SAS programs that run in batch mode. One can (interactively) run a selected portion of code in SAS interface, but in batch we don't have that luxury, while often need to stop/terminate SAS process/session when a certain condition occurs (for example, a source file does not exist). That is where ENDSAS global statement comes very handy. I describe such usage in the following blog posts:
and
Adaptive SAS programming for the Software Development Life Cycle
NOTE: In some SAS docs, it is incorrectly stated that "ENDSAS is most useful in interactive or windowing sessions."
ENDSAS or constructs like ABORT ABEND are not advisable when run from client applications like EG or DI Studio or SAS Studio -- because they terminate the SAS session, dispose of all temporary results, and deny the client application any opportunity to retrieve any in-process ODS results and other artifacts. It's like hanging up the phone in the middle of a conversation, but the receiving party has no idea why...
It is useful in batch and perhaps interactive local SAS, where you want the SAS session to end and stop consuming resources...and you have access to the artifacts that might have been created thus far (including a log file).
If using the same program in batch and in a client like EG, conditional logic can be used to avoid the ENDSAS path in one environment but allow it in the other.
DI Studio works in a bit diffrent way than Base SAS windowing environment. DI Studio is a Java application, and when using the main windows, wizards etc it interacts with the Metadata Server.
When you execute your jobs in DI Studio, you create a server side SAS session through a mechanism called Workspace Server. This SAS session will terminate when it encounters the ENDSAS statement. The DI Studio interface is not dependant on the status of your submitted SAS code.
DI Studio is a developer tool, not a tool for production execution of code.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.