Hi,
In SAS Studio, how can I programmatically detect if I have an active CAS session?
I compared all macro variables and SAS options between the two situation but found nothing that indicates this.
Thanks,
Bart
I did some more digging and I think I found the answer. I'll leave my previous post up since the macro variable might be useful to some.
But you can use the SESSFOUND Function: https://go.documentation.sas.com/doc/en/pgmsascdc/default/lefunctionsref/p1b4sxnrjxw5y8n1cadgqkdtz8h...
%put doIExist= %sysfunc(sessfound(add_sesion_name_here));
Returns a 0 when a CAS session is not connected to a server and a 1 when the session is connected to a server.
I've found when you create a CAS Session it creates two macro variables(_SESSREF_ and _CASNAME_) with the CAS session name.
However, if you terminate your CAS session or the CAS session times out, those macro variables still exist. So this might not be the best solution but a start.
Run the following code to check if the CAS session conn exists:
cas conn;
/* Check for a specific cas session */
%if &_SESSREF_=CONN %then %do;
%put 'Yes the macro variable of a cas session does exist';
%end;
%else %do;
%put 'No CAS session';
%end;
Does this help?
What's your specific use case for this?
I did some more digging and I think I found the answer. I'll leave my previous post up since the macro variable might be useful to some.
But you can use the SESSFOUND Function: https://go.documentation.sas.com/doc/en/pgmsascdc/default/lefunctionsref/p1b4sxnrjxw5y8n1cadgqkdtz8h...
%put doIExist= %sysfunc(sessfound(add_sesion_name_here));
Returns a 0 when a CAS session is not connected to a server and a 1 when the session is connected to a server.
You're welcome! I just learned about this function. Great question!
- Peter
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!