BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Anne_A
Quartz | Level 8

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.

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

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.

Data never sleeps

View solution in original post

6 REPLIES 6
Rick_SAS
SAS Super FREQ

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.

Anne_A
Quartz | Level 8
Thank you @Rick_SAS,
That makes perfect sense. DI Studio is not technically an interactive SAS session (documentation cited above mentions "ENDSAS is most useful in interactive or windowing sessions.").
Cheers.
LeonidBatkhan
Lapis Lazuli | Level 10

Rick_SAS,

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:

How to conditionally stop SAS code execution and gracefully terminate SAS session

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

 

ChrisHemedinger
Community Manager

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.

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
LinusH
Tourmaline | Level 20

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.

Data never sleeps

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 connect to databases in SAS Viya

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.

Discussion stats
  • 6 replies
  • 2245 views
  • 10 likes
  • 5 in conversation